|
| 1 | +// eslint-disable-next-line @typescript-eslint/no-var-requires |
| 2 | +const path = require('node:path') |
| 3 | + |
| 4 | +const project = path.join(__dirname, 'tsconfig.json') |
| 5 | + |
| 6 | +/** @type {import("eslint").Linter.RulesRecord} */ |
| 7 | +const generalRules = { |
| 8 | + 'no-self-compare': 'error', |
| 9 | + 'no-unused-private-class-members': 'error', |
| 10 | + 'no-constant-binary-expression': 'error', |
| 11 | + camelcase: ['error', { ignoreImports: false }], |
| 12 | + 'default-case': 'error', |
| 13 | + 'default-case-last': 'error', |
| 14 | + eqeqeq: 'warn', |
| 15 | + 'func-name-matching': 'error', |
| 16 | + 'logical-assignment-operators': 'error', |
| 17 | + 'new-cap': 'error', |
| 18 | + 'no-array-constructor': 'error', |
| 19 | + 'no-caller': 'error', |
| 20 | + 'no-console': 'error', |
| 21 | + 'no-empty-function': 'off', |
| 22 | + 'no-empty-static-block': 'error', |
| 23 | + 'no-eval': 'error', |
| 24 | + 'no-implied-eval': 'error', |
| 25 | + 'no-new-func': 'error', |
| 26 | + 'no-extend-native': 'error', |
| 27 | + 'no-extra-bind': 'error', |
| 28 | + 'no-extra-label': 'error', |
| 29 | + 'no-label-var': 'error', |
| 30 | + 'no-lonely-if': 'error', |
| 31 | + 'no-multi-assign': 'error', |
| 32 | + 'no-new-wrappers': 'error', |
| 33 | + 'no-proto': 'error', |
| 34 | + 'no-return-assign': 'error', |
| 35 | + 'no-throw-literal': 'error', |
| 36 | + 'no-unneeded-ternary': 'error', |
| 37 | + 'no-useless-computed-key': 'error', |
| 38 | + 'no-useless-constructor': 'off', |
| 39 | + 'no-useless-return': 'error', |
| 40 | + 'operator-assignment': 'error', |
| 41 | + 'prefer-const': 'warn', |
| 42 | + 'prefer-exponentiation-operator': 'error', |
| 43 | + 'prefer-object-spread': 'error', |
| 44 | + 'prefer-regex-literals': 'error', |
| 45 | + 'prefer-spread': 'error', |
| 46 | + 'require-await': 'warn', |
| 47 | + 'symbol-description': 'warn', |
| 48 | + 'no-inner-declarations': 'off', |
| 49 | + 'no-unused-expressions': 'error', |
| 50 | +} |
| 51 | + |
| 52 | +/** @type {import("eslint").Linter.RulesRecord} */ |
| 53 | +const generalRulesForTypeScript = { |
| 54 | + '@typescript-eslint/consistent-type-imports': [ |
| 55 | + 'error', |
| 56 | + { |
| 57 | + prefer: 'type-imports', |
| 58 | + fixStyle: 'separate-type-imports', |
| 59 | + }, |
| 60 | + ], |
| 61 | + '@typescript-eslint/no-unused-vars': ['error', { argsIgnorePattern: '^_' }], |
| 62 | + '@typescript-eslint/array-type': ['error', { default: 'array' }], |
| 63 | + '@typescript-eslint/ban-ts-comment': 'off', |
| 64 | + '@typescript-eslint/consistent-generic-constructors': [ |
| 65 | + 'error', |
| 66 | + 'constructor', |
| 67 | + ], |
| 68 | + '@typescript-eslint/consistent-indexed-object-style': ['warn', 'record'], |
| 69 | + '@typescript-eslint/method-signature-style': ['error', 'property'], |
| 70 | + '@typescript-eslint/no-duplicate-enum-values': 'error', |
| 71 | + '@typescript-eslint/no-duplicate-type-constituents': 'error', |
| 72 | + '@typescript-eslint/no-dynamic-delete': 'warn', |
| 73 | + '@typescript-eslint/no-import-type-side-effects': 'error', |
| 74 | + '@typescript-eslint/no-meaningless-void-operator': 'warn', |
| 75 | + '@typescript-eslint/no-redundant-type-constituents': 'warn', |
| 76 | + '@typescript-eslint/no-unnecessary-boolean-literal-compare': 'error', |
| 77 | + '@typescript-eslint/no-unnecessary-condition': 'warn', |
| 78 | + '@typescript-eslint/no-unnecessary-qualifier': 'error', |
| 79 | + '@typescript-eslint/no-unnecessary-type-arguments': 'error', |
| 80 | + '@typescript-eslint/no-unsafe-declaration-merging': 'error', |
| 81 | + '@typescript-eslint/no-unsafe-enum-comparison': 'error', |
| 82 | + '@typescript-eslint/prefer-function-type': 'error', |
| 83 | + '@typescript-eslint/prefer-optional-chain': 'error', |
| 84 | + '@typescript-eslint/prefer-ts-expect-error': 'error', |
| 85 | + '@typescript-eslint/require-array-sort-compare': 'warn', |
| 86 | + '@typescript-eslint/switch-exhaustiveness-check': 'warn', |
| 87 | + '@typescript-eslint/unified-signatures': 'warn', |
| 88 | + '@typescript-eslint/naming-convention': [ |
| 89 | + 'error', |
| 90 | + { |
| 91 | + selector: 'interface', |
| 92 | + format: ['PascalCase'], |
| 93 | + }, |
| 94 | + { |
| 95 | + selector: 'typeLike', |
| 96 | + format: ['PascalCase'], |
| 97 | + }, |
| 98 | + ], |
| 99 | + '@typescript-eslint/no-namespace': 'off', |
| 100 | + '@typescript-eslint/explicit-member-accessibility': [ |
| 101 | + 'error', |
| 102 | + { overrides: { constructors: 'no-public' } }, |
| 103 | + ], |
| 104 | +} |
| 105 | + |
| 106 | +/** @type {import("eslint").Linter.RulesRecord} */ |
| 107 | +const typeCheckingRules = { |
| 108 | + '@typescript-eslint/no-unsafe-argument': 'warn', |
| 109 | + '@typescript-eslint/no-unsafe-assignment': 'warn', |
| 110 | + '@typescript-eslint/no-unsafe-return': 'warn', |
| 111 | + '@typescript-eslint/no-unsafe-member-access': 'warn', |
| 112 | + '@typescript-eslint/no-unsafe-call': 'warn', |
| 113 | + '@typescript-eslint/unbound-method': 'warn', |
| 114 | + '@typescript-eslint/restrict-template-expressions': 'warn', |
| 115 | +} |
| 116 | + |
| 117 | +/** @type {import("eslint").Linter.RulesRecord} */ |
| 118 | +const unicornRules = { |
| 119 | + 'unicorn/better-regex': 'error', |
| 120 | + 'unicorn/custom-error-definition': 'error', |
| 121 | + 'unicorn/error-message': 'error', |
| 122 | + 'unicorn/filename-case': [ |
| 123 | + 'error', |
| 124 | + { |
| 125 | + case: 'camelCase', |
| 126 | + }, |
| 127 | + ], |
| 128 | + 'unicorn/new-for-builtins': 'error', |
| 129 | + 'unicorn/no-array-method-this-argument': 'error', |
| 130 | + 'unicorn/no-array-push-push': 'error', |
| 131 | + 'unicorn/no-empty-file': 'error', |
| 132 | + 'unicorn/no-instanceof-array': 'error', |
| 133 | + 'unicorn/no-unnecessary-await': 'warn', |
| 134 | + 'unicorn/no-useless-fallback-in-spread': 'warn', |
| 135 | + 'unicorn/no-useless-length-check': 'warn', |
| 136 | + 'unicorn/no-useless-spread': 'warn', |
| 137 | + 'unicorn/no-useless-switch-case': 'warn', |
| 138 | + 'unicorn/no-useless-undefined': 'warn', |
| 139 | + 'unicorn/no-zero-fractions': 'error', |
| 140 | + 'unicorn/number-literal-case': 'error', |
| 141 | + 'unicorn/prefer-array-flat-map': 'warn', |
| 142 | + 'unicorn/prefer-math-trunc': 'warn', |
| 143 | + 'unicorn/prefer-modern-math-apis': 'error', |
| 144 | + 'unicorn/prefer-negative-index': 'warn', |
| 145 | + 'unicorn/prefer-node-protocol': 'error', |
| 146 | + 'unicorn/prefer-optional-catch-binding': 'error', |
| 147 | + 'unicorn/prefer-switch': 'warn', |
| 148 | + 'unicorn/throw-new-error': 'error', |
| 149 | +} |
| 150 | + |
| 151 | +/** @type {import("eslint").Linter.RulesRecord} */ |
| 152 | +const spellRules = { |
| 153 | + 'spellcheck/spell-checker': [ |
| 154 | + 'warn', |
| 155 | + { |
| 156 | + comments: true, |
| 157 | + strings: true, |
| 158 | + identifiers: true, |
| 159 | + templates: true, |
| 160 | + lang: 'en_US', |
| 161 | + skipWords: [ |
| 162 | + 'checkbox', |
| 163 | + 'unary', |
| 164 | + 'convertable', |
| 165 | + 'baseexponent', |
| 166 | + 'typeof', |
| 167 | + 'str', |
| 168 | + 'clipboardy', |
| 169 | + 'esm', |
| 170 | + 'cjs', |
| 171 | + 'iife', |
| 172 | + 'dts', |
| 173 | + 'tsconfig', |
| 174 | + 'minify', |
| 175 | + 'rimraf', |
| 176 | + ], |
| 177 | + }, |
| 178 | + ], |
| 179 | +} |
| 180 | + |
| 181 | +/** @type {import("eslint").Linter.RulesRecord} */ |
| 182 | +const jsdocRules = { |
| 183 | + 'jsdoc/check-alignment': 'error', |
| 184 | + 'jsdoc/check-indentation': 'error', |
| 185 | + 'jsdoc/check-tag-names': 'error', |
| 186 | + 'jsdoc/match-description': [ |
| 187 | + 'error', |
| 188 | + { matchDescription: '^\n?([A-Z`\\d_][\\s\\S]*\\.)\\s*$' }, |
| 189 | + ], |
| 190 | + 'jsdoc/no-bad-blocks': ['error', { preventAllMultiAsteriskBlocks: true }], |
| 191 | + 'jsdoc/no-blank-block-descriptions': 'error', |
| 192 | + 'jsdoc/no-blank-blocks': 'error', |
| 193 | + 'jsdoc/no-multi-asterisks': 'error', |
| 194 | + 'jsdoc/require-asterisk-prefix': 'error', |
| 195 | + 'jsdoc/require-hyphen-before-param-description': 'warn', |
| 196 | + 'jsdoc/require-param-description': 'error', |
| 197 | + 'jsdoc/require-param-name': 'error', |
| 198 | + 'jsdoc/require-throws': 'error', |
| 199 | + 'jsdoc/require-jsdoc': 'off', |
| 200 | +} |
| 201 | + |
| 202 | +/** @type {import("eslint").Linter.RulesRecord} */ |
| 203 | +const securityRules = { |
| 204 | + 'security/detect-object-injection': 'warn', |
| 205 | +} |
| 206 | + |
| 207 | +const plugins = [ |
| 208 | + '@typescript-eslint', |
| 209 | + 'unicorn', |
| 210 | + 'spellcheck', |
| 211 | + 'jsdoc', |
| 212 | + 'security', |
| 213 | +] |
| 214 | + |
| 215 | +const extendsFrom = [ |
| 216 | + 'eslint:recommended', |
| 217 | + 'plugin:@typescript-eslint/recommended', |
| 218 | +] |
| 219 | + |
| 220 | +/** @type {import("eslint").Linter.Config} */ |
| 221 | +const config = { |
| 222 | + env: { |
| 223 | + browser: true, |
| 224 | + es2021: true, |
| 225 | + node: true, |
| 226 | + }, |
| 227 | + overrides: [ |
| 228 | + { |
| 229 | + extends: [ |
| 230 | + 'plugin:@typescript-eslint/recommended-requiring-type-checking', |
| 231 | + ], |
| 232 | + files: ['*.ts'], |
| 233 | + parserOptions: { |
| 234 | + project, |
| 235 | + }, |
| 236 | + rules: typeCheckingRules, |
| 237 | + }, |
| 238 | + { |
| 239 | + files: ['test/**'], |
| 240 | + rules: { |
| 241 | + '@typescript-eslint/no-explicit-any': 'off', |
| 242 | + '@typescript-eslint/unbound-method': 'off', |
| 243 | + 'security/detect-object-injection': 'off', |
| 244 | + }, |
| 245 | + }, |
| 246 | + { |
| 247 | + files: ['examples/**'], |
| 248 | + rules: { |
| 249 | + 'no-console': 'off', |
| 250 | + }, |
| 251 | + }, |
| 252 | + { |
| 253 | + files: ['.eslintrc.cjs'], |
| 254 | + rules: { |
| 255 | + 'spellcheck/spell-checker': 'off', |
| 256 | + }, |
| 257 | + }, |
| 258 | + ], |
| 259 | + parser: '@typescript-eslint/parser', |
| 260 | + root: true, |
| 261 | + parserOptions: { |
| 262 | + project, |
| 263 | + ecmaVersion: 'latest', |
| 264 | + sourceType: 'module', |
| 265 | + }, |
| 266 | + settings: {}, |
| 267 | + plugins, |
| 268 | + extends: extendsFrom, |
| 269 | + rules: { |
| 270 | + ...generalRules, |
| 271 | + ...generalRulesForTypeScript, |
| 272 | + ...unicornRules, |
| 273 | + ...spellRules, |
| 274 | + ...jsdocRules, |
| 275 | + ...securityRules, |
| 276 | + }, |
| 277 | +} |
| 278 | + |
| 279 | +module.exports = config |
0 commit comments