1、使用的標准
// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
2、.eslintignore忽略和禁用
vscode下eslint報錯類似word文字報錯:

3、對於vue文件,可以安裝插件

4、項目配置
// http://eslint.org/docs/user-guide/configuring
module.exports = { // 將 ESLint 限制到一個特定的項目,在配置文件里設置 "root": true。ESLint 一旦發現配置文件中有 "root": true,它就會停止在父級目錄中尋找。
root: true, // 檢測ES6代碼
parser: 'babel-eslint', parserOptions: { sourceType: 'module' }, //
env: { browser: true, }, // 消除no-undef影響
globals: { _: true }, // https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard', // required to lint *.vue files
plugins: [ 'vue', 'html' ], // add your custom rules here // 0或’off’:關閉規則。 // 1或’warn’:打開規則,並且作為一個警告(並不會導致檢查不通過)。 // 2或’error’:打開規則,並且作為一個錯誤 (退出碼為1,檢查不通過)。
// 參數說明: // 參數1 : 錯誤等級 // 參數2 : 處理方式
'rules': { 'prefer-promise-reject-errors': 0, 'space-unary-ops': 0, 'no-unused-expressions': 0, 'no-useless-return': 0, 'standard/no-callback-literal': 0, 'import/first': 0, 'import/export': 0, 'no-mixed-operators': 0, 'no-use-before-define': 0, // 允許使用分號
'semi': [0, 'never'], // 允許使用==
'eqeqeq': 0, // 縮進使用不做限制
'indent': 0, // 允許使用tab
'no-tabs': 0, // 函數圓括號之前沒有空格
'space-before-function-paren': [2, "never"], // 不要求塊內空格填充格式
'padded-blocks': 0, // 不限制變量一起聲明
'one-var': 0, // debugger使用
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // 開發模式允許使用console
'no-console': 0, // 條件語句中復制操作符需要用圓括號括起來
'no-cond-assign': [2, 'except-parens'], // 允許使用條件表達式使用常量
'no-constant-condition': 0, // 單行可忽略大括號,多行不可忽略
'curly': [2, 'multi-line'], // 不允許使用var變量
'no-var': 2, // 不允許出現多個空格
'no-multi-spaces': ["error", { ignoreEOLComments: true }], 'camelcase': 0, // 對象字面量的鍵值空格風格
'key-spacing': 2, // if語句包含一個return語句, else就多余
'no-else-return': 2, // 建議將經常出現的數字提取為變量
'no-magic-numbers': [0, {ignoreArrayIndexes: true}], // 不允許重復聲明變量
'no-redeclare': [2, {builtinGlobals: true}], // 立即執行函數風格
'wrap-iife': [2, 'inside'], // 不允許圓括號中出現空格
'space-in-parens': [2, 'never'], // 確保運算符周圍有空格
'space-infix-ops': 2, // 強制點號與屬性同一行
'dot-location': [2, 'property'], // 強制單行代碼使用空格
'block-spacing': [2, 'always'], // 約束for-in使用hasOwnProperty判斷
'guard-for-in': 0, // 采用one true brace style大括號風格
'brace-style': [2, '1tbs', {'allowSingleLine': true}], // 統一逗號周圍空格風格
'comma-spacing': [2, {'before': false, 'after': true}], // 禁止出現多個空行
'no-multiple-empty-lines': [2, {'max': 1, 'maxEOF': 2}], // 允許箭頭函數不使用圓括號
'arrow-parens': 0, // 規范generator函數的使用
'generator-star-spacing': [2, {'before': false, 'after': true}], // 要求在塊級
'lines-around-comment': [2, {'beforeBlockComment': true, 'afterBlockComment': false, 'beforeLineComment': true, 'afterLineComment': false}] } }
