|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +import eslint from '@eslint/js'; |
| 4 | +import tseslint from 'typescript-eslint'; |
| 5 | +import eslintPrettierConfig from 'eslint-plugin-prettier/recommended'; |
| 6 | +import simpleImportSort from 'eslint-plugin-simple-import-sort'; |
| 7 | + |
| 8 | +/** |
| 9 | + * @returns {import('typescript-eslint').ConfigWithExtends} |
| 10 | + */ |
| 11 | +function buildBaseConfig() { |
| 12 | + return { |
| 13 | + extends: [ |
| 14 | + eslint.configs.recommended, |
| 15 | + ...tseslint.configs.strictTypeChecked, |
| 16 | + ], |
| 17 | + languageOptions: { |
| 18 | + parser: tseslint.parser, |
| 19 | + parserOptions: { |
| 20 | + project: './tsconfig.json', |
| 21 | + }, |
| 22 | + }, |
| 23 | + plugins: { |
| 24 | + '@typescript-eslint': tseslint.plugin, |
| 25 | + 'simple-import-sort': simpleImportSort, |
| 26 | + }, |
| 27 | + rules: { |
| 28 | + '@typescript-eslint/consistent-type-definitions': ['error', 'interface'], |
| 29 | + '@typescript-eslint/explicit-member-accessibility': [ |
| 30 | + 'error', |
| 31 | + { |
| 32 | + overrides: { |
| 33 | + constructors: 'no-public', |
| 34 | + }, |
| 35 | + }, |
| 36 | + ], |
| 37 | + '@typescript-eslint/member-ordering': ['warn'], |
| 38 | + '@typescript-eslint/naming-convention': [ |
| 39 | + 'error', |
| 40 | + { |
| 41 | + selector: ['classProperty'], |
| 42 | + format: ['strictCamelCase', 'UPPER_CASE', 'snake_case'], |
| 43 | + leadingUnderscore: 'allow', |
| 44 | + }, |
| 45 | + { |
| 46 | + selector: 'typeParameter', |
| 47 | + format: ['StrictPascalCase'], |
| 48 | + prefix: ['T'], |
| 49 | + }, |
| 50 | + { |
| 51 | + selector: ['typeLike'], |
| 52 | + format: ['StrictPascalCase'], |
| 53 | + }, |
| 54 | + { |
| 55 | + selector: ['function', 'classMethod'], |
| 56 | + format: ['strictCamelCase'], |
| 57 | + leadingUnderscore: 'allow', |
| 58 | + }, |
| 59 | + { |
| 60 | + selector: ['parameter'], |
| 61 | + format: ['strictCamelCase'], |
| 62 | + leadingUnderscore: 'allow', |
| 63 | + }, |
| 64 | + { |
| 65 | + selector: ['variableLike'], |
| 66 | + format: ['strictCamelCase', 'UPPER_CASE', 'snake_case'], |
| 67 | + }, |
| 68 | + ], |
| 69 | + '@typescript-eslint/no-deprecated': 'error', |
| 70 | + '@typescript-eslint/no-duplicate-type-constituents': 'off', |
| 71 | + '@typescript-eslint/no-dynamic-delete': 'error', |
| 72 | + '@typescript-eslint/no-extraneous-class': 'off', |
| 73 | + '@typescript-eslint/no-inferrable-types': 'off', |
| 74 | + '@typescript-eslint/no-empty-interface': 'warn', |
| 75 | + '@typescript-eslint/no-explicit-any': 'error', |
| 76 | + '@typescript-eslint/no-floating-promises': ['error'], |
| 77 | + '@typescript-eslint/no-unsafe-enum-comparison': 'off', |
| 78 | + 'no-magic-numbers': 'off', |
| 79 | + '@typescript-eslint/no-magic-numbers': [ |
| 80 | + 'warn', |
| 81 | + { |
| 82 | + ignore: [0, 1], |
| 83 | + ignoreArrayIndexes: true, |
| 84 | + ignoreEnums: true, |
| 85 | + ignoreReadonlyClassProperties: true, |
| 86 | + }, |
| 87 | + ], |
| 88 | + '@typescript-eslint/no-require-imports': 'error', |
| 89 | + '@typescript-eslint/no-unnecessary-type-arguments': 'off', |
| 90 | + '@typescript-eslint/no-unused-expressions': ['error'], |
| 91 | + '@typescript-eslint/no-useless-constructor': 'error', |
| 92 | + '@typescript-eslint/prefer-for-of': 'error', |
| 93 | + '@typescript-eslint/prefer-nullish-coalescing': ['off'], |
| 94 | + '@typescript-eslint/prefer-optional-chain': 'off', |
| 95 | + '@typescript-eslint/prefer-readonly': ['warn'], |
| 96 | + '@typescript-eslint/promise-function-async': ['error'], |
| 97 | + '@typescript-eslint/require-await': 'off', |
| 98 | + '@typescript-eslint/restrict-plus-operands': [ |
| 99 | + 'error', |
| 100 | + { |
| 101 | + skipCompoundAssignments: false, |
| 102 | + }, |
| 103 | + ], |
| 104 | + '@typescript-eslint/typedef': [ |
| 105 | + 'error', |
| 106 | + { |
| 107 | + arrayDestructuring: true, |
| 108 | + arrowParameter: true, |
| 109 | + memberVariableDeclaration: true, |
| 110 | + objectDestructuring: true, |
| 111 | + parameter: true, |
| 112 | + propertyDeclaration: true, |
| 113 | + variableDeclaration: true, |
| 114 | + }, |
| 115 | + ], |
| 116 | + '@typescript-eslint/unified-signatures': 'error', |
| 117 | + '@typescript-eslint/strict-boolean-expressions': 'error', |
| 118 | + '@typescript-eslint/switch-exhaustiveness-check': [ |
| 119 | + 'error', |
| 120 | + { |
| 121 | + considerDefaultExhaustiveForUnions: true, |
| 122 | + }, |
| 123 | + ], |
| 124 | + '@typescript-eslint/no-unused-vars': [ |
| 125 | + 'warn', |
| 126 | + { |
| 127 | + args: 'all', |
| 128 | + argsIgnorePattern: '^_', |
| 129 | + caughtErrors: 'all', |
| 130 | + caughtErrorsIgnorePattern: '^_', |
| 131 | + destructuredArrayIgnorePattern: '^_', |
| 132 | + varsIgnorePattern: '^_', |
| 133 | + ignoreRestSiblings: true, |
| 134 | + }, |
| 135 | + ], |
| 136 | + 'simple-import-sort/imports': [ |
| 137 | + 'error', |
| 138 | + { |
| 139 | + groups: [['^\\u0000'], ['^node:'], ['^@?\\w'], ['^'], ['^\\.']], |
| 140 | + }, |
| 141 | + ], |
| 142 | + 'sort-keys': [ |
| 143 | + 'error', |
| 144 | + 'asc', |
| 145 | + { |
| 146 | + caseSensitive: false, |
| 147 | + natural: true, |
| 148 | + }, |
| 149 | + ], |
| 150 | + }, |
| 151 | + }; |
| 152 | +} |
| 153 | + |
| 154 | +const baseRules = buildBaseConfig(); |
| 155 | + |
| 156 | +const config = tseslint.config( |
| 157 | + { |
| 158 | + ...baseRules, |
| 159 | + files: ['**/*.ts'], |
| 160 | + ignores: ['**/*.test.ts'], |
| 161 | + }, |
| 162 | + { |
| 163 | + ...baseRules, |
| 164 | + files: ['**/*.test.ts'], |
| 165 | + rules: { |
| 166 | + ...(baseRules.rules ?? {}), |
| 167 | + '@typescript-eslint/no-confusing-void-expression': 'off', |
| 168 | + '@typescript-eslint/unbound-method': 'off', |
| 169 | + '@typescript-eslint/no-magic-numbers': 'off', |
| 170 | + }, |
| 171 | + }, |
| 172 | + /** @type {import('typescript-eslint').ConfigWithExtends} */ ( |
| 173 | + eslintPrettierConfig |
| 174 | + ), |
| 175 | +); |
| 176 | + |
| 177 | +export default [...config]; |
0 commit comments