由於eslint-config-vue已經被廢棄,於是總結了一下eslint-plugin-vue-libs的eslint config配置,如下:
module.exports = {
extends: ['plugin:vue/essential'],
plugins: ['vue-libs'],
parserOptions: {
parser: require.resolve('babel-eslint'),
ecmaVersion: 2017,
sourceType: 'module'
},
env: {
es6: true,
node: true
},
globals: {
document: false,
navigator: false,
window: false
},
rules: {
// 0 禁用此規則 1 不符合規則即給出警告 2 不符合規則即報錯
'accessor-pairs': 2,// 在對象中使用getter/setter
'arrow-spacing': [2, { 'before': true, 'after': true }],// 箭頭函數前后括號
'block-spacing': [2, 'always'],// 塊級作用域縮進 https://eslint.org/docs/rules/block-spacing#rule-details
'brace-style': [2, '1tbs', { 'allowSingleLine': true }],// 大括號風格,允許寫在一行 https://eslint.org/docs/rules/brace-style#require-brace-style-brace-style
'camelcase': [2, { 'properties': 'never' }],// 強制駝峰命名法
'comma-dangle': [2, 'never'],// 對象字面量項尾不能有逗號
'comma-spacing': [2, { 'before': false, 'after': true }],// 逗號前后的空格
'comma-style': [2, 'last'],// 逗號風格,換行時在行首還是行尾
'constructor-super': 2,// 非派生類不能調用super,派生類必須調用super
'curly': [2, 'multi-line'],// 塊級作用域可以不帶大括號 https://eslint.org/docs/rules/curly#require-following-curly-brace-conventions-curly
'dot-location': [2, 'property'],// 對象訪問符的位置,換行的時候在行首 https://eslint.org/docs/rules/dot-location#enforce-newline-before-and-after-dot-dot-location
'eol-last': 2,// 文件以單一的換行符結束
'eqeqeq': [2, 'allow-null'], // 必須使用全等
'generator-star-spacing': [2, { 'before': true, 'after': true }],// generate函數的前后空格
'handle-callback-err': [2, '^(err|error)$' ],// nodejs函數處理錯誤
'indent': [2, 2, { 'SwitchCase': 1 }],// 縮進風格,switch縮進風格
'jsx-quotes': [2, 'prefer-single'],// jsx使用單引號
'key-spacing': [2, { 'beforeColon': false, 'afterColon': true }],// 對象字面量中冒號添加后空格
'keyword-spacing': [2, { 'before': true, 'after': true }],// 關鍵字前后空格
'new-cap': [2, { 'newIsCap': true, 'capIsNew': false }],// 新建對象實例首字母必須大寫
'new-parens': 2,// new時必須加小括號
'no-array-constructor': 2,// 禁止使用數組構造器 https://eslint.org/docs/rules/no-array-constructor#rule-details
'no-caller': 2, // 禁止使用arguments.caller或arguments.callee
'no-class-assign': 2, // 禁止給類賦值
'no-cond-assign': 2,// 禁止在條件表達式中使用賦值語句
'no-const-assign': 2,//禁止修改const聲明的變量
'no-control-regex': 2,//禁止在正則表達式中使用控制字符
'no-delete-var': 2,//不能對var聲明的變量使用delete操作符
'no-dupe-args': 2,//函數參數不能重復
'no-dupe-class-members': 2, //對象成員不能重復
'no-dupe-keys': 2,//在創建對象字面量時不允許鍵重復
'no-duplicate-case': 2,//switch中的case標簽不能重復
'no-empty-character-class': 2,//正則表達式中的[]內容不能為空
'no-empty-pattern': 2,// https://eslint.org/docs/rules/no-empty-pattern#version
'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,//禁止switch穿透
'no-floating-decimal': 2,//禁止省略浮點數中的0 .5 3.
'no-func-assign': 2,//禁止重復的函數聲明
'no-implied-eval': 2,////禁止使用隱式eval
'no-inner-declarations': [2, 'functions'],//禁止在塊語句中使用聲明(變量或函數)
'no-invalid-regexp': 2,//禁止無效的正則表達式
'no-irregular-whitespace': 2,//不能有不規則的空格
'no-iterator': 2,//禁止使用__iterator__ 屬性
'no-label-var': 2,//label名不能與var聲明的變量名相同
'no-labels': [2, { 'allowLoop': false, 'allowSwitch': false }],
'no-lone-blocks': 2,//禁止標簽聲明
'no-mixed-spaces-and-tabs': 2,//禁止混用tab和空格
'no-multi-spaces': [2, { "ignoreEOLComments": true }],//不能用多余的空格
'no-multi-str': 2,//字符串不能用\換行
'no-multiple-empty-lines': [2, { 'max': 1 }],//空行最多不能超過2行
'no-native-reassign': 2,//不能重寫native對象
'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': 2,// https://eslint.org/docs/rules/no-new-wrappers#disallow-primitive-wrapper-instances-no-new-wrappers
'no-obj-calls': 2,//不能調用內置的全局對象,比如Math() JSON()
'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,//禁止在正則表達式字面量中使用多個空格
'no-return-assign': [2, 'except-parens'],//return 語句中不能有賦值表達式
'no-self-assign': 2,// 不能自聲明
'no-self-compare': 2,// 不能自比較
'no-sequences': 2,//禁止使用逗號運算符
'no-shadow-restricted-names': 2,//嚴格模式中規定的限制標識符不能作為聲明時的變量名使用
'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, { 'defaultAssignment': false }],//禁止不必要的嵌套 https://eslint.org/docs/rules/no-unneeded-ternary#disallow-ternary-operators-when-simpler-alternatives-exist-no-unneeded-ternary
'no-unreachable': 2,//不能有無法執行的代碼
'no-unsafe-finally': 2,// finally中不能執行有歧義的代碼
'no-unused-vars': [2, { 'vars': 'all', 'args': 'none' }],//不聲明未使用的變量
'no-useless-call': 2,//禁止不必要的call和apply
'no-useless-computed-key': 2,//不聲明無用的鍵
'no-useless-constructor': 2,// https://eslint.org/docs/rules/no-useless-constructor#disallow-unnecessary-constructor-no-useless-constructor
'no-useless-escape': 0,// https://eslint.org/docs/rules/no-useless-escape#disallow-unnecessary-escape-usage-no-useless-escape
'no-whitespace-before-property': 2,// 對象鍵之前無空格
'no-with': 2,//禁用with
'one-var': [2, { 'initialized': 'never' }],//禁用連續聲明
'operator-linebreak': [2, 'after', { '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, 'always'],//函數定義時括號前面需要有空格
'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'],// generate 函數 yeild風格
'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'],//是否允許非空數組里面有多余的空格
'vue-libs/jsx-uses-vars': 2,
'vue/require-v-for-key': 0
}
}