/** * @description: eslint检查规则 * @creater: liupw * @date: 2021/10/15 14:33 */ const { defineConfig } = require('eslint-define-config') module.exports = defineConfig({ root: true, env: { browser: true, node: true, es6: true, }, parser: 'vue-eslint-parser', parserOptions: { parser: '@typescript-eslint/parser', ecmaVersion: 2020, sourceType: 'module', ecmaFeatures: { jsx: true, }, }, extends: [ 'plugin:vue/vue3-recommended', 'plugin:@typescript-eslint/recommended', 'prettier', 'plugin:prettier/recommended', ], rules: { 'no-dupe-keys': 2, //在创建对象字面量时不允许键重复 {a:1,a:1} 'no-console': 2, //禁止使用console 'no-const-assign': 2, //禁止修改const声明的变量 'no-constant-condition': 2, //禁止在条件中使用常量表达式 if(true) if(1) 'no-debugger': 2, //禁止使用debugger 'no-dupe-args': 2, //函数参数不能重复 'no-duplicate-case': 2, //switch中的case标签不能重复 'no-else-return': 2, //如果if语句里面有return,后面不能跟else语句 'no-ex-assign': 2, //禁止给catch语句中的异常参数赋值 'no-floating-decimal': 2, //禁止省略浮点数中的0 .5 3. 'no-func-assign': 2, //禁止重复的函数声明 'no-irregular-whitespace': 2, //不能有不规则的空格 'no-multi-spaces': 0, //不能用多余的空格 'no-multiple-empty-lines': [1, { max: 3 }], //空行最多不能超过2行 'no-var': 0, //禁用var,用let和const代替 'no-duplicate-case': 2, // 禁止出现重复的 case 标签 'no-extra-semi': 2, // 禁止不必要的分号 'comma-spacing': 0, //逗号前后的空格 'comma-style': [2, 'last'], //逗号风格,换行时在行首还是行尾 //'no-unused-vars': 2,// 禁止出现未使用过的变量 'no-use-before-define': 2, // 不允许在变量定义之前使用它们 'no-mixed-spaces-and-tabs': 2, // 不允许空格和 tab 混合缩进 'no-trailing-spaces': 2, // 禁用行尾空格 'spaced-comment': 2, // 强制在注释中 // 或 /* 使用一致的空格 '@typescript-eslint/ban-ts-ignore': 'off', '@typescript-eslint/explicit-function-return-type': 'off', '@typescript-eslint/no-explicit-any': 'off', '@typescript-eslint/no-var-requires': 'off', '@typescript-eslint/no-empty-function': 'off', '@typescript-eslint/no-use-before-define': 'off', '@typescript-eslint/ban-ts-comment': 'off', '@typescript-eslint/ban-types': 'off', '@typescript-eslint/no-non-null-assertion': 'off', '@typescript-eslint/explicit-module-boundary-types': 'off', '@typescript-eslint/no-this-alias': [ 'error', { allowDestructuring: false, // Disallow `const { props, state } = this`; true by default allowedNames: ['self'], // Allow `const self = this`; `[]` by default }, ], 'vue/custom-event-name-casing': 'off', 'vue/attributes-order': 'off', 'vue/one-component-per-file': 'off', 'vue/html-closing-bracket-newline': 'off', 'vue/max-attributes-per-line': 'off', 'vue/multiline-html-element-content-newline': 'off', 'vue/singleline-html-element-content-newline': 'off', 'vue/attribute-hyphenation': 'off', 'vue/require-default-prop': 'off', 'vue/html-self-closing': [ 'error', { html: { void: 'always', normal: 'never', component: 'always', }, svg: 'always', math: 'always', }, ], }, })