欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

vue-cli構(gòu)建的項目如何手動添加eslint配置

 更新時間:2022年04月15日 10:10:37   作者:RyanxChen  
這篇文章主要介紹了vue-cli構(gòu)建的項目如何手動添加eslint配置,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教

package.json里配置添加

1.scripts里添加快捷eslint檢查命令

"lint": "eslint --ext .js,.vue src"

2.添加eslint依賴包

"babel-eslint": "^8.2.1",
? ? "eslint": "^4.15.0",
? ? "eslint-config-standard": "^10.2.1",
? ? "eslint-friendly-formatter": "^3.0.0",
? ? "eslint-loader": "^1.7.1",
? ? "eslint-plugin-import": "^2.7.0",
? ? "eslint-plugin-node": "^5.2.0",
? ? "eslint-plugin-promise": "^3.4.0",
? ? "eslint-plugin-standard": "^3.0.1",
? ? "eslint-plugin-vue": "^4.0.0",

根目錄下添加檢測配置js文件.eslintrc.js

// https://eslint.org/docs/user-guide/configuring
module.exports = {
? root: true,
? parserOptions: {
? ? parser: 'babel-eslint'
? },
? env: {
? ? browser: true,
? },
? extends: [
? ? // https://github.com/vuejs/eslint-plugin-vue#priority-a-essential-error-prevention
? ? // consider switching to `plugin:vue/strongly-recommended` or `plugin:vue/recommended` for stricter rules.
? ? 'plugin:vue/essential',?
? ? // https://github.com/standard/standard/blob/master/docs/RULES-en.md
? ? 'standard'
? ],
? // required to lint *.vue files
? plugins: [
? ? 'vue'
? ],
? // add your custom rules here
? rules: {
? ? // allow async-await
? ? 'generator-star-spacing': 'off',
? ? // allow debugger during development
? ? 'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off'
? }
}

添加忽略檢測配置文件.eslintignore

/build/
/config/
/dist/
/*.js

webpack.base.conf.js rules里添加eslint-loader配置

const createLintingRule = () => ({
? test: /\.(js|vue)$/,
? loader: 'eslint-loader',
? enforce: 'pre',
? include: [resolve('src'), resolve('test')],
? options: {
? ? formatter: require('eslint-friendly-formatter'),
? ? emitWarning: !config.dev.showEslintErrorsInOverlay
? }
})
module.exports = {
? //.......
? module: {
? ? rules: [
? ? ? ...(config.dev.useEslint ? [createLintingRule()] : []),
? ? //.....

config->index.js的dev里添加

useEslint: true,
showEslintErrorsInOverlay: false,

Eslint的一些規(guī)則說明

1.使用Eslint的時候如果出現(xiàn)未閉合標(biāo)簽會報紅

如下:

對于有強迫癥的我來說不能無視,怎么搞定?

首先找到 .eslintrc.js文件

rules 添加以下規(guī)則

"vue/html-self-closing": ["error",{
  "html": {
    "void": "never",
    "normal": "any",
    "component": "any"
  },
  "svg": "always",
  "math": "always"
}],

保存即可

2.需要在單行元素的內(nèi)容之前和之后換行

規(guī)則:

"vue/singleline-html-element-content-newline": false,

以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論