建立.eslintrc.js文件放到項目根目錄下便可html
module.exports = { root: true,//此項是用來告訴eslint找當前配置文件不能往父級查找 //此項是用來指定javaScript語言類型和風格,sourceType用來指定js導入的方式,默認是script,此處設置爲module,指某塊導入方式 parserOptions: { parser: 'babel-eslint', sourceType: 'module' }, //此項指定環境的全局變量,下面的配置指定爲瀏覽器環境 env: { browser: true, node: true, es6: true, }, extends: \['plugin:vue/recommended', 'eslint:recommended'\], // add your custom rules here //it is base on https://github.com/vuejs/eslint-config-vue // 下面這些rules是用來設置從插件來的規範代碼的規則,使用必須去掉前綴eslint-plugin- // 主要有以下的設置規則,能夠設置字符串也能夠設置數字,二者效果一致 // "off" -> 0 關閉規則 // "warn" -> 1 開啓警告規則 //"error" -> 2 開啓錯誤規則 rules: { "vue/max-attributes-per-line": \[2, { "singleline": 10, "multiline": { "max": 1, "allowFirstLine": false } }\], "vue/html-indent": \["error", 2, { // 類型 number :縮進的空格數 tab : tab縮進 "attribute": 1, "baseIndent": 1, "closeBracket": 0, "alignAttributesVertically": true, "ignores": \[\] }\], "vue/singleline-html-element-content-newline": "off",// 在單行元素的內容先後須要換行符 "vue/multiline-html-element-content-newline":"off",// 在多行元素的內容以前和以後須要換行符 "vue/name-property-casing": \["error", "PascalCase"\],// JS/JSX中的組件名應該始終是帕斯卡命名法 "vue/no-v-html": "off", "vue/html-self-closing": \["error", { "html": { "void": "never", "normal": "any", "component": "always" }, "svg": "always", "math": "always" }\], 'accessor-pairs': 2,// 在對象中強制使用getter/setter 'arrow-spacing': \[2, { 'before': true, 'after': true }\], 'block-spacing': \[2, 'always'\],//在打開的塊令牌內和同一行上的下一個令牌內強制執行一致的間距。此規則還會在同一行中的關閉塊標記和之前的標記內強制實施一致的間距 'brace-style': \[2, '1tbs', { 'allowSingleLine': true//容許一個塊打開和關閉括號在同一行上 }\],//塊級大括號風格 'camelcase': \[0, {// 須要駝峯命名 'properties': 'always' }\], 'comma-dangle': \[2, 'never'\],// 要求或禁止使用尾隨逗號;最後一個屬性是不須要逗號 'comma-spacing': \[2, {// 強制逗號旁邊的間距: 左右一個空格 'before': false, 'after': true }\], 'comma-style': \[2, 'last'\],// 逗號風格 'constructor-super': 2,// 構建方法中使用super方法 'curly': \[2, 'multi-line'\],//必須使用 if(){} 中的{} 'dot-location': \[2, 'property'\],// 在dot以前和以後強制換行 'eol-last': 2,// 在文件末尾要求或禁止換行 'eqeqeq': \["error", "always", {"null": "ignore"}\],// 是否使用全等 'generator-star-spacing': \[2, {// 在生成器函數中強制執行\*周圍的間距 'before': true, 'after': true }\], 'handle-callback-err': \[0, '^(err|error)$'\],// 強制執行回調錯誤處理 'indent': \[2, 2, {// 強制執行一致的縮進 'SwitchCase': 1 }\], 'jsx-quotes': \[2, 'prefer-single'\],// 強制在JSX文件中一導致用單引號 'key-spacing': \[2, {// 關鍵字先後強制執行一致的間距 'beforeColon': false, 'afterColon': true }\], 'keyword-spacing': \[2, {//對象字面量中冒號的先後空格 'before': true, 'after': true }\], 'new-cap': \[2, {//函數名首行大寫必須使用new方式調用,首行小寫必須用不帶new方式調用 'newIsCap': true, 'capIsNew': false }\], 'new-parens': 2,//new時必須加小括號 'no-array-constructor': 2,//禁止使用數組構造器 'no-caller': 2,//禁止使用arguments.caller或arguments.callee 'no-console': 'off',//禁止使用console 'no-class-assign': 2,//禁止給類賦值 'no-cond-assign': 2,//禁止在條件表達式中使用賦值語句 'no-const-assign': 2,//禁止修改const聲明的變量 'no-control-regex': 0,//禁止在正則表達式中使用控制字符 'no-delete-var': 2,//不能對var聲明的變量使用delete操做符 'no-dupe-args': 2,//函數參數不能重複 'no-dupe-class-members': 2, 'no-dupe-keys': 2,//在建立對象字面量時不容許鍵重複 {a:1,a:1} 'no-duplicate-case': 2,//switch中的case標籤不能重複 'no-empty-character-class': 2,//正則表達式中的\[\]內容不能爲空 'no-empty-pattern': 2,// 禁止使用空解構模式no-empty-pattern 'no-eval': 2,//禁止使用eval 'no-ex-assign': 2,//禁止給catch語句中的異常參數賦值 'no-extend-native': 2,//禁止擴展native對象 'no-extra-bind': 2,//禁止沒必要要的函數綁定 'no-extra-boolean-cast': 2,//禁止沒必要要的bool轉換 'no-extra-parens': \[2, 'functions'\],//禁止非必要的括號 'no-fallthrough': 2,// 禁止 case 語句落空 'no-floating-decimal': 2,// 禁止數字字面量中使用前導和末尾小數點 'no-func-assign': 2,//不容許從新分配function聲明 'no-implied-eval': 2,// 禁止使用相似 eval() 的方法 'no-inner-declarations': \[2, 'functions'\],//在嵌套塊中禁止function聲明 'no-invalid-regexp': 2,//不容許RegExp構造函數中的無效正則表達式字符串 'no-irregular-whitespace': 2,//捕獲無效的空格 'no-iterator': 2,//防止使用該\_\_iterator\_\_屬性時可能出現的錯誤 'no-label-var': 2,//禁止建立與範圍內的變量共享名稱的標籤的不良作法來建立更清晰的代碼 'no-labels': \[2, { 'allowLoop': false,//忽略粘貼到循環語句的標籤 'allowSwitch': false//忽略粘貼到開關語句的標籤 }\],//禁止使用帶標籤的語句 'no-lone-blocks': 2,//消除腳本頂層或其餘塊中沒必要要的和可能混淆的塊 'no-mixed-spaces-and-tabs': 2,//此規則不容許使用混合空格和製表符進行縮進 'no-multi-spaces': 2,//禁止在邏輯表達式,條件表達式,聲明,數組元素,對象屬性,序列和函數參數周圍使用多個空格 'no-multi-str': 2,//規則旨在防止使用多行字符串 'no-multiple-empty-lines': \[2, { 'max': 1 }\],// 強制連續空行的最大數量。 'no-native-reassign': 2,//規則不容許修改只讀全局變量 window,undefined... 'no-negated-in-lhs': 2,//不容許否認in表達式中的左操做數 'no-new-object': 2,//禁止new Object() 'no-new-require': 2,//消除new require表達的使用 'no-new-symbol': 2,//防止Symbol與new操做員的意外呼叫 'no-new-wrappers': 0,//杜絕使用String,Number以及Boolean與new操做 'no-obj-calls': 2,//不容許調用Math,JSON和Reflect對象做爲功能 'no-octal': 2,// 不容許使用八進制文字 'no-octal-escape': 2,// 不容許字符串文字中的八進制轉義序列 'no-path-concat': 2,//node中不能使用\_\_dirname或\_\_filename作路徑拼接 'no-proto': 2,// 禁止使用\_\_proto\_\_屬性 'no-redeclare': 2,//禁止重複聲明變量 'no-regex-spaces': 2,//禁止在正則表達式字面量中使用多個空格 /foo bar/ 'no-return-assign': \[2, 'except-parens'\],//return 語句中不能有賦值表達式 'no-self-assign': 2,//自我分配無效(不能賦值給自身) 'no-self-compare': 2,//不能比較自身 'no-sequences': 2,//禁止使用逗號運算符 'no-shadow-restricted-names': 2,//嚴格模式中規定的限制標識符不能做爲聲明時的變量名使用(NaN,Infinity,undefined,eval和arguments等) 'no-spaced-func': 2,//函數調用時 函數名與()之間不能有空格 'no-sparse-arrays': 2,//禁止稀疏數組, \[1,,2\] 'no-this-before-super': 2,//在調用super()以前不能使用this或super 'no-throw-literal': 2,//禁止拋出字面量錯誤 throw "error"; 'no-trailing-spaces': 2,//一行結束後面不要有空格 'no-undef': 2,//不能有未定義的變量 'no-undef-init': 2,//變量初始化時不能直接給它賦值爲undefined 'no-unexpected-multiline': 2,//避免多行表達式 'no-unmodified-loop-condition': 2, 'no-unneeded-ternary': \[2, {//禁止沒必要要的嵌套 var isYes = answer === 1 ? true : false; 'defaultAssignment': false }\], 'no-unreachable': 2,//不能有沒法執行的代碼 'no-unsafe-finally': 2, //不容許return,throw,break,和continue裏面的語句finally塊 'no-unused-vars': \[2, {//不能有聲明後未被使用的變量或參數 'vars': 'all', 'args': 'none' }\], 'no-useless-call': 2,//禁止沒必要要的call和apply 'no-useless-computed-key': 2, 'no-useless-constructor': 2, 'no-useless-escape': 0, 'no-whitespace-before-property': 2, 'no-with': 2,//禁用with 'one-var': \[0, {//連續聲明 'initialized': 'never' }\], 'operator-linebreak': \[2, 'before', {//換行時運算符在行尾仍是行首 'overrides': { '?': 'before', ':': 'before' } }\], 'padded-blocks': \[2, 'never'\],//塊語句內行首行尾是否要空行 'quotes': \[2, 'single', {//引號類型 \`\` "" '' 'avoidEscape': true, 'allowTemplateLiterals': true }\], 'semi': \[2, 'never'\],//語句強制分號結尾 'semi-spacing': \[2, {//分號先後空格 'before': false, 'after': true }\], 'space-before-blocks': \[2, 'always'\],//不以新行開始的塊{前面要不要有空格 'space-before-function-paren': \[2, 'never'\],//函數定義時括號前面要不要有空格 'space-in-parens': \[2, 'never'\],//小括號裏面要不要有空格 'space-infix-ops': 2,//中綴操做符周圍要不要有空格(須要) 'space-unary-ops': \[2, {//一元運算符的前/後要不要加空格 'words': true, 'nonwords': false }\], 'spaced-comment': \[2, 'always', {//註釋風格要不要有空格什麼的 'markers': \['global', 'globals', 'eslint', 'eslint-disable', '\*package', '!', ','\] }\], 'template-curly-spacing': \[2, 'never'\], //不容許大括號內的空格存在 'use-isnan': 2,//禁止比較時使用NaN,只能用isNaN() 'valid-typeof': 2,//必須使用合法的typeof的值 'wrap-iife': \[2, 'any'\],//當即執行函數表達式的小括號風格 'yield-star-spacing': \[2, 'both'\], 'yoda': \[2, 'never'\],//禁止尤達條件 'prefer-const': 2,//首選const 'no-debugger': process.env.NODE\_ENV\==='production'?2:0,//禁止使用debugger 'object-curly-spacing': \[2, 'always', {//大括號內是否容許沒必要要的空格 objectsInObjects: false }\], 'array-bracket-spacing': \[2, 'never'\]//是否容許非空數組裏面有多餘的空格 } }