|
| 1 | +// @ts-check |
| 2 | + |
| 3 | +import eslint from "@eslint/js"; |
| 4 | +import importX from "eslint-plugin-import-x"; |
| 5 | +import jsdoc from "eslint-plugin-jsdoc"; |
| 6 | +import prettierRecommended from "eslint-plugin-prettier/recommended"; |
| 7 | +import sonarjs from "eslint-plugin-sonarjs"; |
| 8 | +import sortDestructureKeys from "eslint-plugin-sort-destructure-keys"; |
| 9 | +import globals from "globals"; |
| 10 | +import tseslint from "typescript-eslint"; |
| 11 | + |
| 12 | +export default tseslint.config( |
| 13 | + eslint.configs.recommended, |
| 14 | + tseslint.configs.strictTypeChecked, |
| 15 | + tseslint.configs.stylisticTypeChecked, |
| 16 | + jsdoc.configs["flat/recommended-typescript-error"], |
| 17 | + importX.flatConfigs.recommended, |
| 18 | + importX.flatConfigs.typescript, |
| 19 | + prettierRecommended, |
| 20 | + sonarjs.configs.recommended, |
| 21 | + { |
| 22 | + plugins: { |
| 23 | + jsdoc, |
| 24 | + "sort-destructure-keys": sortDestructureKeys, |
| 25 | + }, |
| 26 | + linterOptions: { |
| 27 | + reportUnusedDisableDirectives: true, |
| 28 | + }, |
| 29 | + languageOptions: { |
| 30 | + parserOptions: { |
| 31 | + project: [ |
| 32 | + "tsconfig.json", |
| 33 | + "tsconfig.test.json", |
| 34 | + "packages/*/tsconfig.json", |
| 35 | + "packages/*/tsconfig.test.json", |
| 36 | + "tsconfig.eslint.json", |
| 37 | + ], |
| 38 | + tsconfigRootDir: import.meta.dirname, |
| 39 | + }, |
| 40 | + globals: { ...globals.browser }, |
| 41 | + }, |
| 42 | + rules: { |
| 43 | + "@typescript-eslint/restrict-plus-operands": [ |
| 44 | + "error", |
| 45 | + { allowAny: true, allowNumberAndString: true }, |
| 46 | + ], |
| 47 | + "@typescript-eslint/restrict-template-expressions": [ |
| 48 | + "error", |
| 49 | + { allowAny: true, allowBoolean: true, allowNullish: true, allowNumber: true }, |
| 50 | + ], |
| 51 | + "@typescript-eslint/consistent-indexed-object-style": "off", |
| 52 | + "@typescript-eslint/consistent-type-definitions": "off", // TS treats types and interfaces differently, this may break some advanced type gymnastics |
| 53 | + "@typescript-eslint/consistent-type-imports": [ |
| 54 | + "error", |
| 55 | + { prefer: "type-imports", disallowTypeAnnotations: false }, |
| 56 | + ], |
| 57 | + "@typescript-eslint/dot-notation": ["error", { allowIndexSignaturePropertyAccess: true }], |
| 58 | + "@typescript-eslint/no-confusing-void-expression": "off", |
| 59 | + "@typescript-eslint/no-empty-function": "off", |
| 60 | + "@typescript-eslint/no-empty-object-type": "off", |
| 61 | + "@typescript-eslint/no-explicit-any": "off", |
| 62 | + "@typescript-eslint/no-invalid-void-type": "off", |
| 63 | + "@typescript-eslint/no-namespace": "off", |
| 64 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 65 | + "@typescript-eslint/no-unnecessary-type-parameters": "off", |
| 66 | + "@typescript-eslint/no-unsafe-argument": "off", |
| 67 | + "@typescript-eslint/no-unsafe-assignment": "off", |
| 68 | + "@typescript-eslint/no-unsafe-call": "off", |
| 69 | + "@typescript-eslint/no-unsafe-member-access": "off", |
| 70 | + "@typescript-eslint/no-unsafe-return": "off", |
| 71 | + "@typescript-eslint/no-unused-vars": "off", // Already covered by `tsconfig.json` |
| 72 | + "@typescript-eslint/prefer-nullish-coalescing": "off", |
| 73 | + "@typescript-eslint/prefer-optional-chain": "off", // This library targets ES2015, so optional chaining is not available |
| 74 | + "@typescript-eslint/unified-signatures": "off", |
| 75 | + "import-x/consistent-type-specifier-style": ["error", "prefer-top-level"], |
| 76 | + "import-x/no-named-as-default-member": "off", |
| 77 | + "import-x/no-unresolved": "off", |
| 78 | + "import-x/order": [ |
| 79 | + "error", |
| 80 | + { |
| 81 | + alphabetize: { order: "asc" }, |
| 82 | + groups: ["builtin", "external", "internal", "parent", "sibling", "index", "object"], |
| 83 | + "newlines-between": "always", |
| 84 | + }, |
| 85 | + ], |
| 86 | + "jsdoc/check-param-names": "off", |
| 87 | + "jsdoc/check-tag-names": "off", |
| 88 | + "jsdoc/check-values": "off", |
| 89 | + "jsdoc/require-jsdoc": "off", |
| 90 | + "jsdoc/require-param": "off", |
| 91 | + "jsdoc/require-returns-description": "off", |
| 92 | + "jsdoc/tag-lines": "off", |
| 93 | + "no-restricted-syntax": [ |
| 94 | + "error", |
| 95 | + { |
| 96 | + selector: "CallExpression[callee.property.name='push'] > SpreadElement.arguments", |
| 97 | + message: |
| 98 | + "Do not use spread arguments in `Array#push`, " + |
| 99 | + "as it might cause stack overflow if you spread a large array. " + |
| 100 | + "Instead, use `Array#concat` or `Array.prototype.push.apply`.", |
| 101 | + }, |
| 102 | + ], |
| 103 | + "no-undef": "off", // Already checked by TypeScript |
| 104 | + "object-shorthand": "error", |
| 105 | + "sonarjs/class-name": ["error", { format: "^_?[A-Z][a-zA-Z0-9]*$" }], |
| 106 | + "sonarjs/code-eval": "off", // Already covered by `@typescript-eslint/no-implied-eval` |
| 107 | + "sonarjs/cognitive-complexity": "off", |
| 108 | + "sonarjs/deprecation": "off", // Already covered by `@typescript-eslint/no-deprecated` |
| 109 | + "sonarjs/different-types-comparison": "off", // Already checked by TypeScript |
| 110 | + "sonarjs/no-alphabetical-sort": "off", |
| 111 | + "sonarjs/no-control-regex": "off", // Already covered by `no-control-regex` |
| 112 | + "sonarjs/no-ignored-exceptions": "off", |
| 113 | + "sonarjs/no-nested-assignment": "off", |
| 114 | + "sonarjs/no-nested-conditional": "off", |
| 115 | + "sonarjs/no-nested-functions": "off", |
| 116 | + "sonarjs/no-selector-parameter": "off", |
| 117 | + "sonarjs/no-useless-intersection": "off", // Already checked by TypeScript |
| 118 | + "sonarjs/no-unused-vars": "off", // Already checked by TypeScript |
| 119 | + "sonarjs/reduce-initial-value": "off", |
| 120 | + "sonarjs/redundant-type-aliases": "off", // Already covered by `@typescript-eslint/no-restricted-type-imports` |
| 121 | + "sonarjs/regex-complexity": "off", |
| 122 | + "sonarjs/todo-tag": "off", |
| 123 | + "sonarjs/void-use": "off", |
| 124 | + "sort-destructure-keys/sort-destructure-keys": "error", |
| 125 | + "sort-imports": ["error", { ignoreDeclarationSort: true }], |
| 126 | + }, |
| 127 | + }, |
| 128 | + { |
| 129 | + files: ["**/*.spec.ts"], |
| 130 | + rules: { |
| 131 | + "sonarjs/no-primitive-wrappers": "off", |
| 132 | + }, |
| 133 | + }, |
| 134 | +); |
0 commit comments