網上找了很多配置,一開始也是一頭霧水,最終自己整理了一下。
一、創建vue項目的時候使用了eslint檢查代碼,vs code 安裝eslint插件。
二、.eslintrc.js 網上各種配置都有,最終找到一個可用的
/** * AlloyTeam ESLint 規則 * * 包含所有 ESLint 規則 * 使用 babel-eslint 作為解析器 * * @fixable 表示此配置支持 --fix * @off 表示此配置被關閉了,並且后面說明了關閉的原因 */ module.exports = { parser: 'babel-eslint', parserOptions: { ecmaVersion: 2017, sourceType: 'module', ecmaFeatures: { // @TODO Deprecated https://eslint.org/docs/user-guide/configuring#deprecated experimentalObjectRestSpread: true, jsx: true, modules: true } }, env: { browser: true, node: true, commonjs: true, es6: true }, // 以當前目錄為根目錄,不再向上查找 .eslintrc.js root: true, rules: { // // // 可能的錯誤 // 這些規則與 JavaScript 代碼中可能的語法錯誤或邏輯錯誤有關 // // 禁止 for 循環出現方向錯誤的循環,比如 for (i = 0; i < 10; i--) 'for-direction': 'error', // getter 必須有返回值,並且禁止返回空,比如 return; 'getter-return': [ 'error', { allowImplicit: false } ], // 禁止將 await 寫在循環里,因為這樣就無法同時發送多個異步請求了 // @off 要求太嚴格了,有時需要在循環中寫 await 'no-await-in-loop': 'off', // 禁止與負零進行比較 'no-compare-neg-zero': 'error', // 禁止在測試表達式中使用賦值語句,除非這個賦值語句被括號包起來了 'no-cond-assign': [ 'error', 'except-parens' ], // 禁止使用 console // @off console 的使用很常見 'no-console': 'off', // 禁止將常量作為分支條件判斷中的測試表達式,但允許作為循環條件判斷中的測試表達式 'no-constant-condition': [ 'error', { checkLoops: false } ], // 禁止在正則表達式中出現 Ctrl 鍵的 ASCII 表示,即禁止使用 /\x1f/ // @off 幾乎不會遇到這種場景 'no-control-regex': 'off', // @fixable 禁止使用 debugger 'no-debugger': 'error', // 禁止在函數參數中出現重復名稱的參數 'no-dupe-args': 'error', // 禁止在對象字面量中出現重復名稱的鍵名 'no-dupe-keys': 'error', // 禁止在 switch 語句中出現重復測試表達式的 case 'no-duplicate-case': 'error', // 禁止出現空代碼塊,允許 catch 為空代碼塊 'no-empty': [ 'error', { allowEmptyCatch: true } ], // 禁止在正則表達式中使用空的字符集 [] 'no-empty-character-class': 'error', // 禁止將 catch 的第一個參數 error 重新賦值 'no-ex-assign': 'error', // @fixable 禁止不必要的布爾類型轉換,比如 !! 或 Boolean 'no-extra-boolean-cast': 'error', // @fixable 禁止函數表達式中出現多余的括號,比如 let foo = (function () { return 1 }) 'no-extra-parens': [ 'error', 'functions' ], // @fixable 禁止出現多余的分號 'no-extra-semi': 'error', // 禁止將一個函數聲明重新賦值,如: // function foo() {} // foo = bar 'no-func-assign': 'error', // 禁止在 if 代碼塊內出現函數聲明 'no-inner-declarations': [ 'error', 'both' ], // 禁止在 RegExp 構造函數中出現非法的正則表達式 'no-invalid-regexp': 'error', // 禁止使用特殊空白符(比如全角空格),除非是出現在字符串、正則表達式或模版字符串中 'no-irregular-whitespace': [ 'error', { skipStrings: true, skipComments: false, skipRegExps: true, skipTemplates: true } ], // 禁止將 Math, JSON 或 Reflect 直接作為函數調用 'no-obj-calls': 'error', // 禁止使用 hasOwnProperty, isPrototypeOf 或 propertyIsEnumerable // @off hasOwnProperty 比較常用 'no-prototype-builtins': 'off', // @fixable 禁止在正則表達式中出現連續的空格,必須使用 /foo {3}bar/ 代替 'no-regex-spaces': 'error', // 禁止在數組中出現連續的逗號,如 let foo = [,,] 'no-sparse-arrays': 'error', // 禁止在普通字符串中出現模版字符串里的變量形式,如 'Hello ${name}!' 'no-template-curly-in-string': 'error', // 禁止出現難以理解的多行表達式,如: // let foo = bar // [1, 2, 3].forEach(baz); 'no-unexpected-multiline': 'error', // 禁止在 return, throw, break 或 continue 之后還有代碼 'no-unreachable': 'error', // 禁止在 finally 中出現 return, throw, break 或 continue 'no-unsafe-finally': 'error', // @fixable 禁止在 in 或 instanceof 操作符的左側使用感嘆號,如 if (!key in object) 'no-unsafe-negation': 'error', // 必須使用 isNaN(foo) 而不是 foo === NaN 'use-isnan': 'error', // 注釋必須符合 jsdoc 的規范 // @off jsdoc 要求太嚴格 'valid-jsdoc': 'off', // typeof 表達式比較的對象必須是 'undefined', 'object', 'boolean', 'number', 'string', 'function' 或 'symbol' 'valid-typeof': 'error', // // // 最佳實踐 // 這些規則通過一些最佳實踐幫助你避免問題 // // setter 必須有對應的 getter,getter 可以沒有對應的 setter 'accessor-pairs': [ 'error', { setWithoutGet: true, getWithoutSet: false } ], // 數組的方法除了 forEach 之外,回調函數必須有返回值 'array-callback-return': 'error', // 將 var 定義的變量視為塊作用域,禁止在塊外使用 'block-scoped-var': 'error', // 在類的非靜態方法中,必須存在對 this 的引用 // @off 太嚴格了 'class-methods-use-this': 'off', // 禁止函數的循環復雜度超過 20,https://en.wikipedia.org/wiki/Cyclomatic_complexity 'complexity': [ 'error', { max: 20 } ], // 禁止函數在不同分支返回不同類型的值 // @off 太嚴格了 'consistent-return': 'off', // @fixable if 后面必須要有 {,除非是單行 if 'curly': [ 'error', 'multi-line', 'consistent' ], // switch 語句必須有 default // @off 太嚴格了 'default-case': 'off', // @fixable 鏈式調用的時候,點號必須放在第二行開頭處,禁止放在第一行結尾處 'dot-location': [ 'error', 'property' ], // @fixable 禁止出現 foo['bar'],必須寫成 foo.bar // @off 當需要寫一系列屬性的時候,可以更統一 'dot-notation': 'off', // @fixable 必須使用 === 或 !==,禁止使用 == 或 !=,與 null 比較時除外 'eqeqeq': [ 'error', 'always', { null: 'ignore' } ], // for in 內部必須有 hasOwnProperty 'guard-for-in': 'error', // 禁止使用 alert // @off alert 很常用 'no-alert': 'off', // 禁止使用 caller 或 callee 'no-caller': 'error', // switch 的 case 內有變量定義的時候,必須使用大括號將 case 內變成一個代碼塊 'no-case-declarations': 'error', // 禁止在正則表達式中出現形似除法操作符的開頭,如 let a = /=foo/ // @off 有代碼高亮的話,在閱讀這種代碼時,也完全不會產生歧義或理解上的困難 'no-div-regex': 'off', // @fixable 禁止在 else 內使用 return,必須改為提前結束 // @off else 中使用 return 可以使代碼結構更清晰 'no-else-return': 'off', // 不允許有空函數,除非是將一個空函數設置為某個項的默認值 'no-empty-function': [ 'error', { allow: [ 'functions', 'arrowFunctions' ] } ], // 禁止解構中出現空 {} 或 [] 'no-empty-pattern': 'error', // 禁止使用 foo == null 或 foo != null,必須使用 foo === null 或 foo !== null // @off foo == null 用於判斷 foo 不是 undefined 並且不是 null,比較常用,故允許此寫法 'no-eq-null': 'off', // 禁止使用 eval 'no-eval': 'error', // 禁止修改原生對象 'no-extend-native': 'error', // @fixable 禁止出現沒必要的 bind 'no-extra-bind': 'error', // @fixable 禁止出現沒必要的 label 'no-extra-label': 'error', // switch 的 case 內必須有 break, return 或 throw 'no-fallthrough': 'error', // @fixable 表示小數時,禁止省略 0,比如 .5 'no-floating-decimal': 'error', // 禁止對全局變量賦值 'no-global-assign': 'error', // @fixable 禁止使用 !! ~ 等難以理解的運算符 // 僅允許使用 !! 'no-implicit-coercion': [ 'error', { allow: [ '!!' ] } ], // 禁止在全局作用域下定義變量或申明函數 'no-implicit-globals': 'error', // 禁止在 setTimeout 或 setInterval 中傳入字符串,如 setTimeout('alert("Hi!")', 100); 'no-implied-eval': 'error', // 禁止在類之外的地方使用 this // @off this 的使用很靈活,事件回調中可以表示當前元素,函數也可以先用 this,等以后被調用的時候再 call 'no-invalid-this': 'off', // 禁止使用 __iterator__ 'no-iterator': 'error', // 禁止使用 label 'no-labels': 'error', // 禁止使用沒必要的 {} 作為代碼塊 'no-lone-blocks': 'error', // 禁止在循環內的函數中出現循環體條件語句中定義的變量,比如: // for (var i = 0; i < 10; i++) { // (function () { return i })(); // } 'no-loop-func': 'error', // 禁止使用 magic numbers // @off 太嚴格了 'no-magic-numbers': 'off', // @fixable 禁止出現連續的多個空格,除非是注釋前,或對齊對象的屬性、變量定義、import 等 'no-multi-spaces': [ 'error', { ignoreEOLComments: true, exceptions: { Property: true, BinaryExpression: false, VariableDeclarator: true, ImportDeclaration: true } } ], // 禁止使用 \ 來換行字符串 'no-multi-str': 'error', // 禁止直接 new 一個類而不賦值 'no-new': 'error', // 禁止使用 new Function,比如 let x = new Function("a", "b", "return a + b"); 'no-new-func': 'error', // 禁止使用 new 來生成 String, Number 或 Boolean 'no-new-wrappers': 'error', // 禁止使用 0 開頭的數字表示八進制數 'no-octal': 'error', // 禁止使用八進制的轉義符 'no-octal-escape': 'error', // 禁止對函數的參數重新賦值 'no-param-reassign': 'error', // 禁止使用 __proto__ 'no-proto': 'error', // 禁止重復定義變量 'no-redeclare': 'error', // 禁止使用指定的對象屬性 // @off 它用於限制某個具體的 api 不能使用 'no-restricted-properties': 'off', // 禁止在 return 語句里賦值 'no-return-assign': [ 'error', 'always' ], // 禁止在 return 語句里使用 await 'no-return-await': 'error', // 禁止出現 location.href = 'javascript:void(0)'; 'no-script-url': 'error', // 禁止將自己賦值給自己 'no-self-assign': 'error', // 禁止將自己與自己比較 'no-self-compare': 'error', // 禁止使用逗號操作符 'no-sequences': 'error', // 禁止 throw 字面量,必須 throw 一個 Error 對象 'no-throw-literal': 'error', // 循環內必須對循環條件的變量有修改 'no-unmodified-loop-condition': 'error', // 禁止無用的表達式 'no-unused-expressions': [ 'error', { allowShortCircuit: true, allowTernary: true, allowTaggedTemplates: true } ], // @fixable 禁止出現沒用的 label 'no-unused-labels': 'error', // 禁止出現沒必要的 call 或 apply 'no-useless-call': 'error', // 禁止出現沒必要的字符串連接 'no-useless-concat': 'error', // 禁止出現沒必要的轉義 // @off 轉義可以使代碼更易懂 'no-useless-escape': 'off', // @fixable 禁止沒必要的 return // @off 沒必要限制 return 'no-useless-return': 'off', // 禁止使用 void 'no-void': 'error', // 禁止注釋中出現 TODO 和 FIXME // @off TODO 很常用 'no-warning-comments': 'off', // 禁止使用 with 'no-with': 'error', // Promise 的 reject 中必須傳入 Error 對象,而不是字面量 'prefer-promise-reject-errors': 'error', // parseInt 必須傳入第二個參數 'radix': 'error', // async 函數中必須存在 await 語句 // @off async function 中沒有 await 的寫法很常見,比如 koa 的示例中就有這種用法 'require-await': 'off', // var 必須在作用域的最前面 // @off var 不在最前面也是很常見的用法 'vars-on-top': 'off', // @fixable 立即執行的函數必須符合如下格式 (function () { alert('Hello') })() 'wrap-iife': [ 'error', 'inside', { functionPrototypeMethods: true } ], // @fixable 必須使用 if (foo === 5) 而不是 if (5 === foo) 'yoda': [ 'error', 'never', { onlyEquality: true } ], // // // 嚴格模式 // 這些規則與嚴格模式指令有關 // // @fixable 禁止使用 'strict'; 'strict': [ 'error', 'never' ], // // // 變量 // 這些規則與變量申明有關 // // 變量必須在定義的時候賦值 // @off 先定義后賦值很常見 'init-declarations': 'off', // 禁止 catch 的參數名與定義過的變量重復 // @off 太嚴格了 'no-catch-shadow': 'off', // 禁止使用 delete 'no-delete-var': 'error', // 禁止 label 名稱與定義過的變量重復 'no-label-var': 'error', // 禁止使用指定的全局變量 // @off 它用於限制某個具體的變量名不能使用 'no-restricted-globals': 'off', // 禁止變量名與上層作用域內的定義過的變量重復 // @off 很多時候函數的形參和傳參是同名的 'no-shadow': 'off', // 禁止使用保留字作為變量名 'no-shadow-restricted-names': 'error', // 禁止使用未定義的變量 'no-undef': [ 'error', { typeof: false } ], // @fixable 禁止將 undefined 賦值給變量 'no-undef-init': 'error', // 禁止對 undefined 重新賦值 'no-undefined': 'error', // 定義過的變量必須使用 'no-unused-vars': [ 'error', { vars: 'all', args: 'none', caughtErrors: 'none', ignoreRestSiblings: true } ], // 變量必須先定義后使用 'no-use-before-define': [ 'error', { functions: false, classes: false, variables: false } ], // // // Node.js 和 CommonJS // 這些規則與在 Node.js 中運行的代碼或瀏覽器中使用的 CommonJS 有關 // // callback 之后必須立即 return // @off Limitations 太多了 'callback-return': 'off', // require 必須在全局作用域下 // @off 條件加載很常見 'global-require': 'off', // callback 中的 error 必須被處理 'handle-callback-err': 'error', // 禁止直接使用 Buffer 'no-buffer-constructor': 'error', // 相同類型的 require 必須放在一起 // @off 太嚴格了 'no-mixed-requires': 'off', // 禁止直接 new require('foo') 'no-new-require': 'error', // 禁止對 __dirname 或 __filename 使用字符串連接 'no-path-concat': 'error', // 禁止使用 process.env.NODE_ENV // @off 使用很常見 'no-process-env': 'off', // 禁止使用 process.exit(0) // @off 使用很常見 'no-process-exit': 'off', // 禁止使用指定的模塊 // @off 它用於限制某個具體的模塊不能使用 'no-restricted-modules': 'off', // 禁止使用 node 中的同步的方法,比如 fs.readFileSync // @off 使用很常見 'no-sync': 'off', // // // 風格問題 // 這些規則與代碼風格有關,所以是非常主觀的 // // @fixable 配置數組的中括號內前后的換行格式 // @off 配置項無法配制成想要的樣子 'array-bracket-newline': 'off', // @fixable 數組的括號內的前后禁止有空格 'array-bracket-spacing': [ 'error', 'never' ], // @fixable 配置數組的元素之間的換行格式 // @off 允許一行包含多個元素,方便大數量的數組的書寫 'array-element-newline': 'off', // @fixable 代碼塊如果在一行內,那么大括號內的首尾必須有空格,比如 function () { alert('Hello') } 'block-spacing': [ 'error', 'always' ], // @fixable if 與 else 的大括號風格必須一致 // @off else 代碼塊可能前面需要有一行注釋 'brace-style': 'off', // 變量名必須是 camelcase 風格的 // @off 很多 api 或文件名都不是 camelcase 'camelcase': 'off', // @fixable 注釋的首字母必須大寫 // @off 沒必要限制 'capitalized-comments': 'off', // @fixable 對象的最后一個屬性末尾必須有逗號 // @off 沒必要限制 'comma-dangle': 'off', // @fixable 逗號前禁止有空格,逗號后必須要有空格 'comma-spacing': [ 'error', { 'before': false, 'after': true } ], // @fixable 禁止在行首寫逗號 'comma-style': [ 'error', 'last' ], // @fixable 用作對象的計算屬性時,中括號內的首尾禁止有空格 'computed-property-spacing': [ 'error', 'never' ], // 限制 this 的別名 // @off 沒必要限制 'consistent-this': 'off', // @fixable 文件最后一行必須有一個空行 // @off 沒必要限制 'eol-last': 'off', // @fixable 函數名和執行它的括號之間禁止有空格 'func-call-spacing': [ 'error', 'never' ], // 函數賦值給變量的時候,函數名必須與變量名一致 'func-name-matching': [ 'error', 'always', { includeCommonJSModuleExports: false } ], // 函數必須有名字 // @off 沒必要限制 'func-names': 'off', // 必須只使用函數聲明或只使用函數表達式 // @off 沒必要限制 'func-style': 'off', // 禁止使用指定的標識符 // @off 它用於限制某個具體的標識符不能使用 'id-blacklist': 'off', // 限制變量名長度 // @off 沒必要限制變量名長度 'id-length': 'off', // 限制變量名必須匹配指定的正則表達式 // @off 沒必要限制變量名 'id-match': 'off', // @fixable 一個縮進必須用四個空格替代 'indent': [ 'off', 2, { SwitchCase: 1, flatTernaryExpressions: true } ], // @fixable jsx 中的屬性必須用雙引號 'jsx-quotes': [ 'error', 'prefer-double' ], // @fixable 對象字面量中冒號前面禁止有空格,后面必須有空格 'key-spacing': [ 'error', { beforeColon: false, afterColon: true, mode: 'strict', } ], // @fixable 關鍵字前后必須有空格 'keyword-spacing': [ 'error', { before: true, after: true } ], // 單行注釋必須寫在上一行 // @off 沒必要限制 'line-comment-position': 'off', // @fixable 限制換行符為 LF 或 CRLF // @off 沒必要限制 'linebreak-style': 'off', // @fixable 注釋前后必須有空行 // @off 沒必要限制 'lines-around-comment': 'off', // 代碼塊嵌套的深度禁止超過 5 層 'max-depth': [ 'error', 5 ], // 限制一行的長度 // @off 現在編輯器已經很智能了,不需要限制一行的長度 'max-len': 'off', // 限制一個文件最多的行數 // @off 沒必要限制 'max-lines': 'off', // 回調函數嵌套禁止超過 3 層,多了請用 async await 替代 'max-nested-callbacks': [ 'error', 3 ], // 函數的參數禁止超過 7 個 'max-params': [ 'error', 7 ], // 限制函數塊中的語句數量 // @off 沒必要限制 'max-statements': 'off', // 限制一行中的語句數量 // @off 沒必要限制 'max-statements-per-line': 'off', // 三元表達式必須得換行 // @off 三元表達式可以隨意使用 'multiline-ternary': 'off', // new 后面的類名必須首字母大寫 'new-cap': [ 'error', { newIsCap: true, capIsNew: false, properties: true } ], // @fixable new 后面的類必須有小括號 'new-parens': 'error', // 鏈式調用必須換行 // @off 沒必要限制 'newline-per-chained-call': 'off', // 禁止使用 Array 構造函數 'no-array-constructor': 'error', // 禁止使用位運算 // @off 位運算很常見 'no-bitwise': 'off', // 禁止使用 continue // @off continue 很常用 'no-continue': 'off', // 禁止在代碼后添加內聯注釋 // @off 內聯注釋很常用 'no-inline-comments': 'off', // @fixable 禁止 else 中只有一個單獨的 if // @off 單獨的 if 可以把邏輯表達的更清楚 'no-lonely-if': 'off', // 禁止混用不同的操作符,比如 let foo = a && b < 0 || c > 0 || d + 1 === 0 // @off 太嚴格了,可以由使用者自己去判斷如何混用操作符 'no-mixed-operators': 'off', // 禁止混用空格和縮進 'no-mixed-spaces-and-tabs': 'error', // 禁止連續賦值,比如 a = b = c = 5 // @off 沒必要限制 'no-multi-assign': 'off', // @fixable 禁止出現超過三行的連續空行 'no-multiple-empty-lines': [ 'error', { max: 3, maxEOF: 1, maxBOF: 1 } ], // 禁止 if 里面有否定的表達式,比如: // if (a !== b) { // doSomething(); // } else { // doSomethingElse(); // } // @off 否定的表達式可以把邏輯表達的更清楚 'no-negated-condition': 'off', // 禁止使用嵌套的三元表達式,比如 a ? b : c ? d : e // @off 沒必要限制 'no-nested-ternary': 'off', // 禁止直接 new Object 'no-new-object': 'error', // 禁止使用 ++ 或 -- // @off 沒必要限制 'no-plusplus': 'off', // 禁止使用特定的語法 // @off 它用於限制某個具體的語法不能使用 'no-restricted-syntax': 'off', // 禁止使用 tabs 'no-tabs': 'error', // 禁止使用三元表達式 // @off 三元表達式很常用 'no-ternary': 'off', // @fixable 禁止行尾有空格 'no-trailing-spaces': 'error', // 禁止變量名出現下划線 // @off 下划線在變量名中很常用 'no-underscore-dangle': 'off', // @fixable 必須使用 !a 替代 a ? false : true // @off 后者表達的更清晰 'no-unneeded-ternary': 'off', // @fixable 禁止屬性前有空格,比如 foo. bar() 'no-whitespace-before-property': 'error', // @fixable 禁止 if 后面不加大括號而寫兩行代碼 'nonblock-statement-body-position': [ 'error', 'beside', { overrides: { while: 'below' } } ], // @fixable 大括號內的首尾必須有換行 'object-curly-newline': [ 'error', { multiline: true, consistent: true } ], // @fixable 對象字面量只有一行時,大括號內的首尾必須有空格 'object-curly-spacing': [ 'error', 'always', { arraysInObjects: true, objectsInObjects: false } ], // @fixable 對象字面量內的屬性每行必須只有一個 // @off 沒必要限制 'object-property-newline': 'off', // 禁止變量申明時用逗號一次申明多個 'one-var': [ 'error', 'never' ], // @fixable 變量申明必須每行一個 'one-var-declaration-per-line': [ 'error', 'always' ], // @fixable 必須使用 x = x + y 而不是 x += y // @off 沒必要限制 'operator-assignment': 'off', // @fixable 需要換行的時候,操作符必須放在行末,比如: // let foo = 1 + // 2 // @off 有時放在第二行開始處更易讀 'operator-linebreak': 'off', // @fixable 代碼塊首尾必須要空行 // @off 沒必要限制 'padded-blocks': 'off', // @fixable 限制語句之間的空行規則,比如變量定義完之后必須要空行 // @off 沒必要限制 'padding-line-between-statements': 'off', // @fixable 對象字面量的鍵名禁止用引號括起來 // @off 沒必要限制 'quote-props': 'off', // @fixable 必須使用單引號,禁止使用雙引號 'quotes': [ 'error', 'single', { avoidEscape: true, allowTemplateLiterals: true } ], // 必須使用 jsdoc 風格的注釋 // @off 太嚴格了 'require-jsdoc': 'off', // @fixable 結尾必須有分號 'semi': [ 'error', 'always', { omitLastInOneLineBlock: true } ], // @fixable 一行有多個語句時,分號前面禁止有空格,分號后面必須有空格 'semi-spacing': [ 'error', { before: false, after: true } ], // @fixable 分號必須寫在行尾,禁止在行首出現 'semi-style': [ 'error', 'last' ], // 對象字面量的鍵名必須排好序 // @off 沒必要限制 'sort-keys': 'off', // 變量申明必須排好序 // @off 沒必要限制 'sort-vars': 'off', // @fixable if, function 等的大括號之前必須要有空格,比如 if (a) { 'space-before-blocks': [ 'error', 'always' ], // @fixable function 的小括號之前必須要有空格 'space-before-function-paren': [ 'error', { anonymous: 'ignore', named: 'never', asyncArrow: 'always' } ], // @fixable 小括號內的首尾禁止有空格 'space-in-parens': [ 'error', 'never' ], // @fixable 操作符左右必須有空格,比如 let sum = 1 + 2; 'space-infix-ops': 'error', // @fixable new, typeof 等后面必須有空格,++, -- 等禁止有空格,比如: // let foo = new Person(); // bar = bar++; 'space-unary-ops': [ 'error', { words: true, nonwords: false } ], // @fixable 注釋的斜線或 * 后必須有空格 'spaced-comment': [ 'error', 'always', { block: { exceptions: [ '*' ], balanced: true } } ], // @fixable case 的冒號前禁止有空格,冒號后必須有空格 'switch-colon-spacing': [ 'error', { after: true, before: false } ], // @fixable 模版字符串的 tag 之后禁止有空格,比如 tag`Hello World` 'template-tag-spacing': [ 'error', 'never' ], // @fixable 文件開頭禁止有 BOM 'unicode-bom': [ 'error', 'never' ], // @fixable 正則表達式必須有括號包起來 // @off 沒必要限制 'wrap-regex': 'off', // // // ECMAScript 6 // 這些規則與 ES6(即通常所說的 ES2015)有關 // // @fixable 箭頭函數能夠省略 return 的時候,必須省略,比如必須寫成 () => 0,禁止寫成 () => { return 0 } // @off 箭頭函數的返回值,應該允許靈活設置 'arrow-body-style': 'off', // @fixable 箭頭函數只有一個參數的時候,必須加括號 // @off 應該允許靈活設置 'arrow-parens': 'off', // @fixable 箭頭函數的箭頭前后必須有空格 'arrow-spacing': [ 'error', { before: true, after: true } ], // constructor 中必須有 super 'constructor-super': 'error', // @fixable generator 的 * 前面禁止有空格,后面必須有空格 'generator-star-spacing': [ 'error', { before: false, after: true } ], // 禁止對定義過的 class 重新賦值 'no-class-assign': 'error', // @fixable 禁止出現難以理解的箭頭函數,比如 let x = a => 1 ? 2 : 3 'no-confusing-arrow': [ 'error', { allowParens: true } ], // 禁止對使用 const 定義的常量重新賦值 'no-const-assign': 'error', // 禁止重復定義類 'no-dupe-class-members': 'error', // 禁止重復 import 模塊 'no-duplicate-imports': 'error', // 禁止使用 new 來生成 Symbol 'no-new-symbol': 'error', // 禁止 import 指定的模塊 // @off 它用於限制某個具體的模塊不能使用 'no-restricted-imports': 'off', // 禁止在 super 被調用之前使用 this 或 super 'no-this-before-super': 'error', // @fixable 禁止出現沒必要的計算鍵名,比如 let a = { ['0']: 0 }; 'no-useless-computed-key': 'error', // 禁止出現沒必要的 constructor,比如 constructor(value) { super(value) } 'no-useless-constructor': 'error', // @fixable 禁止解構時出現同樣名字的的重命名,比如 let { foo: foo } = bar; 'no-useless-rename': 'error', // @fixable 禁止使用 var 'no-var': 'error', // @fixable 必須使用 a = {b} 而不是 a = {b: b} // @off 沒必要強制要求 'object-shorthand': 'off', // @fixable 必須使用箭頭函數作為回調 // @off 沒必要強制要求 'prefer-arrow-callback': 'off', // @fixable 申明后不再被修改的變量必須使用 const 來申明 // @off 沒必要強制要求 'prefer-const': 'off', // 必須使用解構 // @off 沒必要強制要求 'prefer-destructuring': 'off', // @fixable 必須使用 0b11111011 而不是 parseInt('111110111', 2) // @off 沒必要強制要求 'prefer-numeric-literals': 'off', // 必須使用 ...args 而不是 arguments // @off 沒必要強制要求 'prefer-rest-params': 'off', // @fixable 必須使用 ... 而不是 apply,比如 foo(...args) // @off apply 很常用 'prefer-spread': 'off', // @fixable 必須使用模版字符串而不是字符串連接 // @off 字符串連接很常用 'prefer-template': 'off', // generator 函數內必須有 yield 'require-yield': 'error', // @fixable ... 的后面禁止有空格 'rest-spread-spacing': [ 'error', 'never' ], // @fixable import 必須按規則排序 // @off 沒必要強制要求 'sort-imports': 'off', // 創建 Symbol 時必須傳入參數 'symbol-description': 'error', // @fixable ${name} 內的首尾禁止有空格 'template-curly-spacing': [ 'error', 'never' ], // @fixable yield* 后面必須要有空格 'yield-star-spacing': [ 'error', 'after' ] } };
三、setting.json 文件的位置
四、setting.json 配置
{ "workbench.editor.enablePreview": false, //打開文件不覆蓋 "search.followSymlinks": false, //關閉rg.exe進程 "editor.minimap.enabled": false, //關閉快速預覽 "liveServer.settings.donotShowInfoMsg": true, //關閉liveserver提示 "files.autoSave": "afterDelay", //打開自動保存 "editor.fontSize": 16, //設置文字大小 "editor.lineHeight": 24, //設置文字行高 "editor.lineNumbers": "on", //開啟行數提示 "editor.quickSuggestions": { //開啟自動顯示建議 "other": true, "comments": true, "strings": true }, "window.zoomLevel": 0, // 調整窗口的縮放級別 "editor.tabSize": 2, //制表符符號eslint "editor.formatOnSave": true, //每次保存自動格式化 "prettier.semi": false, //去掉代碼結尾的分號 "prettier.singleQuote": true, //使用帶引號替代雙引號 "javascript.format.insertSpaceBeforeFunctionParenthesis": true, //讓函數(名)和后面的括號之間加個空格 "vetur.format.defaultFormatter.html": "js-beautify-html", //格式化.vue中html "vetur.format.defaultFormatter.js": "vscode-typescript", //讓vue中的js按編輯器自帶的ts格式進行格式化 "vetur.format.defaultFormatterOptions": { "js-beautify-html": { "wrap_attributes": "force-aligned" //屬性強制折行對齊 } }, "editor.codeActionsOnSave": { "source.fixAll.eslint": true }, "editor.suggestSelection": "first", "vsintellicode.modify.editor.suggestSelection": "automaticallyOverrodeDefaultValue", "java.configuration.checkProjectSettingsExclusions": false, "java.errors.incompleteClasspath.severity": "ignore", "breadcrumbs.enabled": true, "editor.renderControlCharacters": false, "vetur.validation.template": false }