|
| 1 | +module.exports = { |
| 2 | + parser: '@typescript-eslint/parser', |
| 3 | + parserOptions: { |
| 4 | + project: 'tsconfig.json', |
| 5 | + tsconfigRootDir: __dirname, |
| 6 | + ecmaVersion: 'latest', |
| 7 | + sourceType: 'module', |
| 8 | + }, |
| 9 | + root: true, |
| 10 | + env: { |
| 11 | + node: true, |
| 12 | + jest: true, |
| 13 | + }, |
| 14 | + plugins: ['@typescript-eslint', 'jest', 'prettier', 'import', 'unused-imports'], |
| 15 | + extends: [ |
| 16 | + // airbnb规范 |
| 17 | + // https://github.com/airbnb/javascript/tree/master/packages/eslint-config-airbnb |
| 18 | + 'airbnb-base', |
| 19 | + // 兼容typescript的airbnb规范 |
| 20 | + // https://github.com/iamturns/eslint-config-airbnb-typescript |
| 21 | + 'airbnb-typescript/base', |
| 22 | + |
| 23 | + // typescript的eslint插件 |
| 24 | + // https://github.com/typescript-eslint/typescript-eslint/blob/master/docs/getting-started/linting/README.md |
| 25 | + // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin |
| 26 | + 'plugin:@typescript-eslint/recommended', |
| 27 | + 'plugin:@typescript-eslint/recommended-requiring-type-checking', |
| 28 | + |
| 29 | + // 支持jest |
| 30 | + 'plugin:jest/recommended', |
| 31 | + // 使用prettier格式化代码 |
| 32 | + // https://github.com/prettier/eslint-config-prettier#readme |
| 33 | + 'prettier', |
| 34 | + // 整合typescript-eslint与prettier, eslint与pretttire冲突时,以prettire为准 |
| 35 | + // https://github.com/prettier/eslint-plugin-prettier |
| 36 | + 'plugin:prettier/recommended', |
| 37 | + ], |
| 38 | + rules: { |
| 39 | + /* ********************************** ES6+ ********************************** */ |
| 40 | + 'no-console': 0, |
| 41 | + 'no-var-requires': 0, |
| 42 | + 'no-restricted-syntax': 0, |
| 43 | + 'no-continue': 0, |
| 44 | + 'no-await-in-loop': 0, |
| 45 | + 'no-return-await': 0, |
| 46 | + 'no-unused-vars': 0, |
| 47 | + 'no-multi-assign': 0, |
| 48 | + 'no-param-reassign': [2, { props: false }], |
| 49 | + 'import/prefer-default-export': 0, |
| 50 | + 'import/no-cycle': 0, |
| 51 | + 'import/no-dynamic-require': 0, |
| 52 | + 'max-classes-per-file': 0, |
| 53 | + 'class-methods-use-this': 0, |
| 54 | + 'guard-for-in': 0, |
| 55 | + 'no-underscore-dangle': 0, |
| 56 | + 'no-plusplus': 0, |
| 57 | + 'no-lonely-if': 0, |
| 58 | + 'no-bitwise': ['error', { allow: ['~'] }], |
| 59 | + |
| 60 | + /* ********************************** Module Import ********************************** */ |
| 61 | + |
| 62 | + 'import/no-absolute-path': 0, |
| 63 | + 'import/extensions': 0, |
| 64 | + 'import/no-named-default': 0, |
| 65 | + 'no-restricted-exports': 0, |
| 66 | + |
| 67 | + // 一部分文件在导入devDependencies的依赖时不报错 |
| 68 | + 'import/no-extraneous-dependencies': [ |
| 69 | + 1, |
| 70 | + { |
| 71 | + devDependencies: ['**/*.test.{ts,js}', '**/*.spec.{ts,js}', './test/**.{ts,js}'], |
| 72 | + }, |
| 73 | + ], |
| 74 | + // 模块导入顺序规则 |
| 75 | + 'import/order': [ |
| 76 | + 1, |
| 77 | + { |
| 78 | + pathGroups: [ |
| 79 | + { |
| 80 | + pattern: '@/**', |
| 81 | + group: 'external', |
| 82 | + position: 'after', |
| 83 | + }, |
| 84 | + ], |
| 85 | + alphabetize: { order: 'asc', caseInsensitive: false }, |
| 86 | + 'newlines-between': 'always-and-inside-groups', |
| 87 | + warnOnUnassignedImports: true, |
| 88 | + }, |
| 89 | + ], |
| 90 | + // 自动删除未使用的导入 |
| 91 | + // https://github.com/sweepline/eslint-plugin-unused-imports |
| 92 | + 'unused-imports/no-unused-imports': 1, |
| 93 | + 'unused-imports/no-unused-vars': [ |
| 94 | + 'error', |
| 95 | + { |
| 96 | + vars: 'all', |
| 97 | + args: 'none', |
| 98 | + ignoreRestSiblings: true, |
| 99 | + }, |
| 100 | + ], |
| 101 | + /* ********************************** Typescript ********************************** */ |
| 102 | + '@typescript-eslint/no-unused-vars': 0, |
| 103 | + '@typescript-eslint/no-empty-interface': 0, |
| 104 | + '@typescript-eslint/no-this-alias': 0, |
| 105 | + '@typescript-eslint/no-var-requires': 0, |
| 106 | + '@typescript-eslint/no-use-before-define': 0, |
| 107 | + '@typescript-eslint/explicit-member-accessibility': 0, |
| 108 | + '@typescript-eslint/no-non-null-assertion': 0, |
| 109 | + '@typescript-eslint/no-unnecessary-type-assertion': 0, |
| 110 | + '@typescript-eslint/require-await': 0, |
| 111 | + '@typescript-eslint/no-for-in-array': 0, |
| 112 | + '@typescript-eslint/interface-name-prefix': 0, |
| 113 | + '@typescript-eslint/explicit-function-return-type': 0, |
| 114 | + '@typescript-eslint/no-explicit-any': 0, |
| 115 | + '@typescript-eslint/explicit-module-boundary-types': 0, |
| 116 | + '@typescript-eslint/no-floating-promises': 0, |
| 117 | + '@typescript-eslint/restrict-template-expressions': 0, |
| 118 | + '@typescript-eslint/no-unsafe-assignment': 0, |
| 119 | + '@typescript-eslint/no-unsafe-return': 0, |
| 120 | + '@typescript-eslint/no-unused-expressions': 0, |
| 121 | + '@typescript-eslint/no-misused-promises': 0, |
| 122 | + '@typescript-eslint/no-unsafe-member-access': 0, |
| 123 | + '@typescript-eslint/no-unsafe-call': 0, |
| 124 | + '@typescript-eslint/no-unsafe-argument': 0, |
| 125 | + '@typescript-eslint/ban-ts-comment': 0, |
| 126 | + }, |
| 127 | + |
| 128 | + settings: { |
| 129 | + extensions: ['.ts', '.d.ts', '.cts', '.mts', '.js', '.cjs', 'mjs', '.json'], |
| 130 | + }, |
| 131 | +}; |
0 commit comments