const { defineConfig } = require('eslint-define-config') const MAX_LEN_OPTIONS = { code: 1500 } const typeScriptRules = { 'no-inferrable-types': 0, 'no-this-alias': 0, 'no-explicit-any': 0, 'ban-types': 0, 'no-non-null-assertion': 0, 'ban-ts-comment': 0, // 这个置为off是因为避免装饰器被分行 'lines-between-class-members': 'off', 'naming-convention': 'off', 'no-unused-expressions': [ 1, { allowShortCircuit: true, allowTernary: true } ], 'no-unused-vars': ['warn', { vars: 'all', // 内联变量,后面的参数被使用了,前面的未被使用会忽略 args: 'after-used', ignoreRestSiblings: false }] } module.exports = defineConfig({ env: { browser: true, es2022: true, node: true }, parser: '@babel/eslint-parser', parserOptions: { ecmaVersion: 'latest', babelOptions: { 'plugins': [ '@babel/plugin-syntax-import-assertions' ] }, requireConfigFile: false, parser: '@typescript-eslint/parser', sourceType: 'module' }, globals: { globalThis: false // means it is not writeable }, root: true, extends: [ 'eslint:recommended', 'plugin:@typescript-eslint/recommended', '@vue/standard' ], plugins: [ 'vue', '@typescript-eslint' ], rules: { 'no-return-assign': 0, 'comma-dangle': 1, 'prefer-rest-params': 0, 'no-fallthrough': 0, 'vue/multi-word-component-names': 0, // 'no-console': process.env.NODE_ENV === 'production' ? ['error', { allow: ['error', 'warn'] }] : 'off', //生产模式不允许使用log // 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off', //生产默认不允许使用debugger // 不强求箭头函数的括号问题 'arrow-parens': 0, 'arrow-body-style': 0, 'max-classes-per-file': 0, // 默认值80有点短,改成150 'max-len': [ 'error', MAX_LEN_OPTIONS ], // 由于一定情况函数实参跟形参类型一样,为了减少变量名,可以重新赋值 'no-param-reassign': 0, // 运许在循环里边使用i++,或者单行的i++,但不建议将i++进行赋值运算 'no-plusplus': 0, 'no-mixed-operators': [ 'error', { groups: [ // 默认值包含算数运算优先级,项目预设所有人应该熟知运算优先级,所以屏蔽掉 // ["+", "-", "*", "/", "%", "**"], ['&', '|', '^', '~', '<<', '>>', '>>>'], ['==', '!=', '===', '!==', '>', '>=', '<', '<='], ['&&', '||'], ['in', 'instanceof'] ], allowSamePrecedence: true } ], 'no-multiple-empty-lines': ['error', { max: 1 }], 'no-unused-expressions': 0, ...Object.keys(typeScriptRules).reduce((memo, ruleKey) => { // ts + js memo[`@typescript-eslint/${ ruleKey }`] = typeScriptRules[ruleKey] memo[ruleKey] = typeScriptRules[ruleKey] return memo }, {}), // 允许下划线变量以及成员 'no-underscore-dangle': 0, // 对于内联的三元运算给予警告,但还是允许编译通过 'no-nested-ternary': 0, 'no-mixed-operators': 0, // 允许使用default进行导入 'import/no-named-as-default': 0, // 不要求全局的require函数,对于动态请求也是不可能要求全局的 'global-require': 0, 'vue/max-len': ['error', MAX_LEN_OPTIONS], 'import/no-cycle': 0, // 'import/no-cycle': ['error', { // ignoreExternal: false, // maxDepth: 3, // }], 'import/order': 0, // 排序请求 // 'import/order': ['error', { // pathGroups: [ // { // pattern: '@/**', // group: 'external', // }, // { // pattern: '_/**', // group: 'external', // }, // ], // groups: ['builtin', 'external', 'parent', 'sibling', 'index'], // }], 'import/no-extraneous-dependencies': 0, // 'import/no-extraneous-dependencies': ['error', { devDependencies: devScope }], 'import/no-relative-packages': 0, 'import/no-self-import': 0, 'import/no-duplicates': 0, // 控制prop默认的default 'vue/require-default-prop': 0 // 'vue/no-setup-props-destructure': 0, // 'function-paren-newline': 0, // 'vue/no-mutating-props': 0, // 'vue/no-multi-spaces': 0, // 'vue/html-button-has-type': 0, }, overrides: [{ // 设置某些文件,禁用部分检查 files: ['*.ts', '*.tsx'], rules: { ...Object.fromEntries(Object.entries(typeScriptRules).map((key) => [key, 0])) } }] })