前端工程化 ESlint 配置

一、使用的標準javascript

// https://github.com/feross/standard/blob/master/RULES.md#javascript-standard-style
extends: 'standard',
 
二、.eslintignore忽略和禁用

vscode下eslint報錯相似word文字報錯:html

三、對於vue文件,能夠安裝插件vue

四、項目配置java

// 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}] } }
相關文章
相關標籤/搜索