|
| 1 | +import eslint from "@eslint/js"; |
| 2 | +import type { Linter } from "eslint"; |
| 3 | +import importPlugin from "eslint-plugin-import"; |
| 4 | +import unicorn from "eslint-plugin-unicorn"; |
| 5 | +import jsdoc from "eslint-plugin-jsdoc"; |
| 6 | +import preferArrow from "eslint-plugin-prefer-arrow"; |
| 7 | +import functional from "eslint-plugin-functional"; |
| 8 | +import globals from "globals"; |
| 9 | +import tsEslint from "typescript-eslint"; |
| 10 | + |
| 11 | +const config: Linter.Config<Linter.RulesRecord>[] = [ |
| 12 | + { |
| 13 | + ignores: ["**/vite.config.ts", "**/build/**", "**/coverage/**", "**/*.js", "eslint.config.ts", "**/demo/**", "**/scripts/**"], |
| 14 | + }, |
| 15 | + eslint.configs.recommended, |
| 16 | + importPlugin.flatConfigs.recommended, |
| 17 | + ...tsEslint.configs.recommended, |
| 18 | + ...tsEslint.configs.stylistic, |
| 19 | + { |
| 20 | + files: ["**/src/**/*.ts"], |
| 21 | + plugins: { |
| 22 | + unicorn, |
| 23 | + jsdoc, |
| 24 | + "prefer-arrow": preferArrow, |
| 25 | + functional, |
| 26 | + }, |
| 27 | + |
| 28 | + languageOptions: { |
| 29 | + parserOptions: { |
| 30 | + projectService: true, |
| 31 | + tsconfigRootDir: import.meta.dirname, |
| 32 | + }, |
| 33 | + }, |
| 34 | + |
| 35 | + settings: { |
| 36 | + "import/resolver": { |
| 37 | + typescript: true, |
| 38 | + node: true, |
| 39 | + }, |
| 40 | + }, |
| 41 | + |
| 42 | + rules: { |
| 43 | + "no-undef": "off", |
| 44 | + "no-extra-boolean-cast": "off", |
| 45 | + "no-alert": "error", |
| 46 | + "no-self-compare": "error", |
| 47 | + "no-unreachable-loop": "error", |
| 48 | + "no-template-curly-in-string": "error", |
| 49 | + "no-unused-private-class-members": "error", |
| 50 | + "no-extend-native": "error", |
| 51 | + "no-floating-decimal": "error", |
| 52 | + "no-implied-eval": "error", |
| 53 | + "no-iterator": "error", |
| 54 | + "no-lone-blocks": "error", |
| 55 | + "no-loop-func": "error", |
| 56 | + "no-new-object": "error", |
| 57 | + "no-proto": "error", |
| 58 | + "no-useless-catch": "error", |
| 59 | + "one-var-declaration-per-line": "error", |
| 60 | + "prefer-arrow-callback": "error", |
| 61 | + "prefer-destructuring": "error", |
| 62 | + "prefer-exponentiation-operator": "error", |
| 63 | + "prefer-promise-reject-errors": "error", |
| 64 | + "prefer-regex-literals": "error", |
| 65 | + "prefer-spread": "error", |
| 66 | + "prefer-template": "error", |
| 67 | + "require-await": "error", |
| 68 | + "@typescript-eslint/adjacent-overload-signatures": "error", |
| 69 | + |
| 70 | + "@typescript-eslint/array-type": [ |
| 71 | + "error", |
| 72 | + { |
| 73 | + default: "array", |
| 74 | + }, |
| 75 | + ], |
| 76 | + |
| 77 | + "@typescript-eslint/no-restricted-types": [ |
| 78 | + "error", |
| 79 | + { |
| 80 | + types: { |
| 81 | + Object: { |
| 82 | + message: "Avoid using the `Object` type. Did you mean `object`?", |
| 83 | + fixWith: "object", |
| 84 | + }, |
| 85 | + |
| 86 | + Function: { |
| 87 | + message: "Avoid using the `Function` type. Prefer a specific function type, like `() => void`.", |
| 88 | + }, |
| 89 | + |
| 90 | + Boolean: { |
| 91 | + message: "Avoid using the `Boolean` type. Did you mean `boolean`?", |
| 92 | + fixWith: "boolean", |
| 93 | + }, |
| 94 | + |
| 95 | + Number: { |
| 96 | + message: "Avoid using the `Number` type. Did you mean `number`?", |
| 97 | + fixWith: "number", |
| 98 | + }, |
| 99 | + |
| 100 | + String: { |
| 101 | + message: "Avoid using the `String` type. Did you mean `string`?", |
| 102 | + fixWith: "string", |
| 103 | + }, |
| 104 | + |
| 105 | + Symbol: { |
| 106 | + message: "Avoid using the `Symbol` type. Did you mean `symbol`?", |
| 107 | + fixWith: "symbol", |
| 108 | + }, |
| 109 | + }, |
| 110 | + }, |
| 111 | + ], |
| 112 | + |
| 113 | + "@typescript-eslint/consistent-type-assertions": "error", |
| 114 | + "@typescript-eslint/dot-notation": "error", |
| 115 | + |
| 116 | + "@typescript-eslint/explicit-function-return-type": [ |
| 117 | + "error", |
| 118 | + { |
| 119 | + allowExpressions: true, |
| 120 | + allowTypedFunctionExpressions: true, |
| 121 | + allowHigherOrderFunctions: false, |
| 122 | + allowDirectConstAssertionInArrowFunctions: true, |
| 123 | + allowConciseArrowFunctionExpressionsStartingWithVoid: true, |
| 124 | + }, |
| 125 | + ], |
| 126 | + |
| 127 | + "@typescript-eslint/explicit-member-accessibility": [ |
| 128 | + "error", |
| 129 | + { |
| 130 | + accessibility: "explicit", |
| 131 | + |
| 132 | + overrides: { |
| 133 | + accessors: "explicit", |
| 134 | + }, |
| 135 | + }, |
| 136 | + ], |
| 137 | + |
| 138 | + "@typescript-eslint/explicit-module-boundary-types": [ |
| 139 | + "error", |
| 140 | + { |
| 141 | + allowArgumentsExplicitlyTypedAsAny: true, |
| 142 | + allowDirectConstAssertionInArrowFunctions: true, |
| 143 | + allowHigherOrderFunctions: false, |
| 144 | + allowTypedFunctionExpressions: false, |
| 145 | + }, |
| 146 | + ], |
| 147 | + |
| 148 | + "@typescript-eslint/naming-convention": [ |
| 149 | + "error", |
| 150 | + { |
| 151 | + selector: ["objectLiteralProperty"], |
| 152 | + leadingUnderscore: "allow", |
| 153 | + format: ["camelCase", "PascalCase", "UPPER_CASE"], |
| 154 | + |
| 155 | + filter: { |
| 156 | + regex: "(^[a-z]+:.+)|_attr|[0-9]", |
| 157 | + match: false, |
| 158 | + }, |
| 159 | + }, |
| 160 | + ], |
| 161 | + |
| 162 | + "@typescript-eslint/no-empty-function": "error", |
| 163 | + "@typescript-eslint/no-empty-interface": "error", |
| 164 | + "@typescript-eslint/no-explicit-any": "error", |
| 165 | + "@typescript-eslint/no-misused-new": "error", |
| 166 | + "@typescript-eslint/no-namespace": "error", |
| 167 | + "@typescript-eslint/no-parameter-properties": "off", |
| 168 | + "@typescript-eslint/no-require-imports": "error", |
| 169 | + |
| 170 | + "@typescript-eslint/no-shadow": [ |
| 171 | + "error", |
| 172 | + { |
| 173 | + hoist: "all", |
| 174 | + }, |
| 175 | + ], |
| 176 | + |
| 177 | + "@typescript-eslint/consistent-type-definitions": ["error", "type"], |
| 178 | + |
| 179 | + "@typescript-eslint/no-this-alias": "error", |
| 180 | + "@typescript-eslint/no-unused-expressions": "error", |
| 181 | + "@typescript-eslint/no-use-before-define": "off", |
| 182 | + "@typescript-eslint/no-var-requires": "error", |
| 183 | + "@typescript-eslint/prefer-for-of": "error", |
| 184 | + "@typescript-eslint/prefer-function-type": "error", |
| 185 | + "@typescript-eslint/prefer-namespace-keyword": "error", |
| 186 | + "@typescript-eslint/prefer-readonly": "error", |
| 187 | + |
| 188 | + "@typescript-eslint/triple-slash-reference": [ |
| 189 | + "error", |
| 190 | + { |
| 191 | + path: "always", |
| 192 | + types: "prefer-import", |
| 193 | + lib: "always", |
| 194 | + }, |
| 195 | + ], |
| 196 | + |
| 197 | + "@typescript-eslint/typedef": [ |
| 198 | + "error", |
| 199 | + { |
| 200 | + parameter: true, |
| 201 | + propertyDeclaration: true, |
| 202 | + }, |
| 203 | + ], |
| 204 | + |
| 205 | + "@typescript-eslint/no-inferrable-types": "off", |
| 206 | + |
| 207 | + "@typescript-eslint/unified-signatures": "error", |
| 208 | + "arrow-body-style": "error", |
| 209 | + complexity: "off", |
| 210 | + "consistent-return": "error", |
| 211 | + "constructor-super": "error", |
| 212 | + curly: "error", |
| 213 | + "dot-notation": "off", |
| 214 | + eqeqeq: ["error", "smart"], |
| 215 | + "guard-for-in": "error", |
| 216 | + |
| 217 | + "id-denylist": ["error", "any", "Number", "number", "String", "string", "Boolean", "boolean", "Undefined", "undefined"], |
| 218 | + |
| 219 | + "id-match": "error", |
| 220 | + "import/no-default-export": "error", |
| 221 | + "import/no-extraneous-dependencies": "off", |
| 222 | + "import/no-internal-modules": "off", |
| 223 | + "sort-imports": [ |
| 224 | + "error", |
| 225 | + { |
| 226 | + allowSeparatedGroups: true, |
| 227 | + ignoreDeclarationSort: true, |
| 228 | + }, |
| 229 | + ], |
| 230 | + "import/order": [ |
| 231 | + "error", |
| 232 | + { |
| 233 | + groups: [["external", "builtin"], "internal", ["sibling", "parent", "index"]], |
| 234 | + "newlines-between": "always", |
| 235 | + pathGroups: [ |
| 236 | + { pattern: "@file/**/*", group: "internal" }, |
| 237 | + { pattern: "@file/**", group: "internal" }, |
| 238 | + { pattern: "@export/**", group: "internal" }, |
| 239 | + ], |
| 240 | + pathGroupsExcludedImportTypes: ["internal"], |
| 241 | + alphabetize: { |
| 242 | + order: "asc", |
| 243 | + caseInsensitive: true, |
| 244 | + }, |
| 245 | + }, |
| 246 | + ], |
| 247 | + indent: "off", |
| 248 | + "jsdoc/check-alignment": "error", |
| 249 | + "jsdoc/check-indentation": "off", |
| 250 | + "max-classes-per-file": "off", |
| 251 | + "max-len": "off", |
| 252 | + "new-parens": "error", |
| 253 | + "no-bitwise": "error", |
| 254 | + "no-caller": "error", |
| 255 | + "no-cond-assign": "error", |
| 256 | + "no-console": "error", |
| 257 | + "no-debugger": "error", |
| 258 | + "no-duplicate-case": "error", |
| 259 | + "no-duplicate-imports": "error", |
| 260 | + "no-empty": "error", |
| 261 | + "no-empty-function": "off", |
| 262 | + "no-eval": "error", |
| 263 | + "no-extra-bind": "error", |
| 264 | + "no-fallthrough": "off", |
| 265 | + "no-invalid-this": "off", |
| 266 | + "no-multiple-empty-lines": "error", |
| 267 | + "no-new-func": "error", |
| 268 | + "no-new-wrappers": "error", |
| 269 | + "no-param-reassign": "error", |
| 270 | + "no-redeclare": "error", |
| 271 | + "no-return-await": "error", |
| 272 | + "no-sequences": "error", |
| 273 | + "no-shadow": "off", |
| 274 | + "no-sparse-arrays": "error", |
| 275 | + "no-throw-literal": "error", |
| 276 | + "no-trailing-spaces": "error", |
| 277 | + "no-undef-init": "error", |
| 278 | + |
| 279 | + "no-underscore-dangle": [ |
| 280 | + "error", |
| 281 | + { |
| 282 | + allow: ["_attr"], |
| 283 | + }, |
| 284 | + ], |
| 285 | + |
| 286 | + "no-unsafe-finally": "error", |
| 287 | + "no-unused-expressions": "off", |
| 288 | + "no-unused-labels": "error", |
| 289 | + "no-use-before-define": "off", |
| 290 | + "no-useless-constructor": "error", |
| 291 | + "no-var": "error", |
| 292 | + "object-shorthand": "off", |
| 293 | + "one-var": ["error", "never"], |
| 294 | + "prefer-arrow/prefer-arrow-functions": "error", |
| 295 | + "prefer-const": "error", |
| 296 | + "prefer-object-spread": "error", |
| 297 | + radix: "error", |
| 298 | + "space-in-parens": ["error", "never"], |
| 299 | + |
| 300 | + "spaced-comment": [ |
| 301 | + "error", |
| 302 | + "always", |
| 303 | + { |
| 304 | + markers: ["/"], |
| 305 | + }, |
| 306 | + ], |
| 307 | + |
| 308 | + "unicorn/filename-case": "error", |
| 309 | + "unicorn/prefer-ternary": "error", |
| 310 | + "use-isnan": "error", |
| 311 | + "valid-typeof": "off", |
| 312 | + |
| 313 | + "functional/immutable-data": [ |
| 314 | + "error", |
| 315 | + { |
| 316 | + ignoreImmediateMutation: true, |
| 317 | + ignoreAccessorPattern: ["**.root*", "**.numberingReferences*", "**.sections*", "**.properties*"], |
| 318 | + }, |
| 319 | + ], |
| 320 | + |
| 321 | + "functional/prefer-property-signatures": "error", |
| 322 | + "functional/no-mixed-types": "error", |
| 323 | + "functional/prefer-readonly-type": "error", |
| 324 | + |
| 325 | + "@typescript-eslint/no-unused-vars": [ |
| 326 | + "error", |
| 327 | + { |
| 328 | + argsIgnorePattern: "^[_]+$", |
| 329 | + }, |
| 330 | + ], |
| 331 | + }, |
| 332 | + }, |
| 333 | + { |
| 334 | + files: ["**/*.spec.ts"], |
| 335 | + plugins: { |
| 336 | + unicorn, |
| 337 | + jsdoc, |
| 338 | + "prefer-arrow": preferArrow, |
| 339 | + functional, |
| 340 | + }, |
| 341 | + languageOptions: { |
| 342 | + globals: { |
| 343 | + ...globals.browser, |
| 344 | + ...globals.node, |
| 345 | + }, |
| 346 | + |
| 347 | + sourceType: "module", |
| 348 | + |
| 349 | + parserOptions: { |
| 350 | + projectService: true, |
| 351 | + tsconfigRootDir: import.meta.dirname, |
| 352 | + project: ["tsconfig.json"], |
| 353 | + }, |
| 354 | + }, |
| 355 | + rules: { |
| 356 | + "@typescript-eslint/no-unused-expressions": "off", |
| 357 | + "@typescript-eslint/dot-notation": "off", |
| 358 | + "prefer-destructuring": "off", |
| 359 | + "@typescript-eslint/explicit-function-return-type": "off", |
| 360 | + "no-unused-vars": [ |
| 361 | + "error", |
| 362 | + { |
| 363 | + argsIgnorePattern: "^[_]+$", |
| 364 | + }, |
| 365 | + ], |
| 366 | + }, |
| 367 | + }, |
| 368 | +]; |
| 369 | + |
| 370 | +export default config; |
0 commit comments