|
| 1 | +import js from "@eslint/js"; |
| 2 | +import globals from "globals"; |
| 3 | +import tseslint from "typescript-eslint"; |
| 4 | +import vitest from "@vitest/eslint-plugin"; |
| 5 | +import stylistic from "@stylistic/eslint-plugin-ts"; |
| 6 | +import { defineConfig } from "eslint/config"; |
| 7 | + |
| 8 | +export default defineConfig([ |
| 9 | + { |
| 10 | + ignores: [ |
| 11 | + 'node_modules/**', |
| 12 | + '*.js', |
| 13 | + '/types/**' |
| 14 | + ] |
| 15 | + }, |
| 16 | + // Base JavaScript configuration |
| 17 | + { |
| 18 | + files: ["**/*.{js,mjs,cjs}"], |
| 19 | + ...js.configs.recommended, |
| 20 | + languageOptions: { |
| 21 | + globals: { |
| 22 | + ...globals.browser, |
| 23 | + ...globals.node, |
| 24 | + ...globals.es2020, |
| 25 | + }, |
| 26 | + }, |
| 27 | + }, |
| 28 | + // TypeScript configuration with all rules |
| 29 | + { |
| 30 | + files: ["**/*.{ts,mts,cts}"], |
| 31 | + plugins: { |
| 32 | + "@typescript-eslint": tseslint.plugin, |
| 33 | + "@stylistic/ts": stylistic, |
| 34 | + }, |
| 35 | + languageOptions: { |
| 36 | + parser: tseslint.parser, |
| 37 | + parserOptions: { |
| 38 | + projectService: true, |
| 39 | + tsconfigRootDir: import.meta.dirname, |
| 40 | + }, |
| 41 | + globals: { |
| 42 | + ...globals.browser, |
| 43 | + ...globals.es2020, |
| 44 | + }, |
| 45 | + }, |
| 46 | + rules: { |
| 47 | + // Base ESLint recommended rules |
| 48 | + ...js.configs.recommended.rules, |
| 49 | + |
| 50 | + // TypeScript ESLint all rules |
| 51 | + ...tseslint.configs.all.find(config => config.rules)?.rules || {}, |
| 52 | + |
| 53 | + // TypeScript ESLint stylistic type-checked rules |
| 54 | + ...tseslint.configs.stylisticTypeChecked.find(config => config.rules)?.rules || {}, |
| 55 | + |
| 56 | + // https://eslint.org/docs/rules/ |
| 57 | + "no-any": "off", |
| 58 | + "no-prototype-builtins": "off", |
| 59 | + "no-unused-vars": "off", |
| 60 | + "prefer-rest-params": "warn", |
| 61 | + "semi": "off", |
| 62 | + "no-extra-parens": "off", |
| 63 | + "quotes": "off", |
| 64 | + "func-call-spacing": "off", |
| 65 | + "comma-spacing": "off", |
| 66 | + "keyword-spacing": "off", |
| 67 | + "object-curly-spacing": ["warn", "always"], |
| 68 | + "indent": "off", |
| 69 | + "comma-dangle": ["warn", "never"], |
| 70 | + "max-len": ["warn", 120], |
| 71 | + "eqeqeq": "error", |
| 72 | + "no-restricted-imports": "off", |
| 73 | + "lines-between-class-members": "off", |
| 74 | + "lines-around-comment": "off", |
| 75 | + |
| 76 | + // https://github.com/typescript-eslint/typescript-eslint/tree/master/packages/eslint-plugin#supported-rules |
| 77 | + '@stylistic/ts/object-curly-spacing': ['warn', 'always'], |
| 78 | + "@stylistic/ts/indent": ["warn", 4], |
| 79 | + "@stylistic/ts/quotes": ["warn", "single"], |
| 80 | + "@stylistic/ts/semi": "error", |
| 81 | + "@stylistic/ts/no-extra-parens": "error", |
| 82 | + "@typescript-eslint/no-unused-vars": "warn", |
| 83 | + "@typescript-eslint/no-useless-constructor": "warn", |
| 84 | + "@typescript-eslint/no-explicit-any": "off", |
| 85 | + "@typescript-eslint/ban-ts-comment": "off", |
| 86 | + "@typescript-eslint/no-unsafe-return": "off", |
| 87 | + "@typescript-eslint/no-unsafe-assignment": "off", |
| 88 | + "@typescript-eslint/explicit-module-boundary-types": ["error", { "allowArgumentsExplicitlyTypedAsAny": true }], |
| 89 | + "@typescript-eslint/prefer-nullish-coalescing": "warn", |
| 90 | + "@typescript-eslint/prefer-optional-chain": "warn", |
| 91 | + "@typescript-eslint/prefer-ts-expect-error": "warn", |
| 92 | + "@typescript-eslint/promise-function-async": "error", |
| 93 | + "@stylistic/ts/func-call-spacing": ["error", "never"], |
| 94 | + "@stylistic/ts/comma-spacing": "warn", |
| 95 | + "@stylistic/ts/keyword-spacing": "warn", |
| 96 | + "@typescript-eslint/consistent-indexed-object-style": ["error", "record"], |
| 97 | + "@typescript-eslint/consistent-type-imports": ["error", { prefer: 'type-imports' }], |
| 98 | + "@stylistic/ts/member-delimiter-style": "warn", |
| 99 | + "@stylistic/ts/type-annotation-spacing": "warn", |
| 100 | + "@typescript-eslint/naming-convention": "error", |
| 101 | + "@typescript-eslint/no-magic-numbers": "off", |
| 102 | + "@typescript-eslint/no-non-null-assertion": "off", |
| 103 | + "@typescript-eslint/member-ordering": "off", |
| 104 | + "@typescript-eslint/class-literal-property-style": "off", |
| 105 | + "@stylistic/ts/space-before-function-paren": ["warn", { |
| 106 | + "anonymous": "always", |
| 107 | + "named": "never", |
| 108 | + "asyncArrow": "always" |
| 109 | + }], |
| 110 | + "@typescript-eslint/prefer-readonly-parameter-types": "off", |
| 111 | + "@typescript-eslint/init-declarations": "off", |
| 112 | + "@typescript-eslint/no-unnecessary-condition": "off", |
| 113 | + "@typescript-eslint/no-type-alias": "off", |
| 114 | + "@typescript-eslint/explicit-function-return-type": "off", |
| 115 | + "@typescript-eslint/consistent-type-definitions": "off", |
| 116 | + "@typescript-eslint/strict-boolean-expressions": "off", |
| 117 | + "@typescript-eslint/no-dynamic-delete": "off", |
| 118 | + "@typescript-eslint/no-loop-func": "off", |
| 119 | + "@typescript-eslint/no-confusing-void-expression": "off", |
| 120 | + "@typescript-eslint/array-type": "warn", |
| 121 | + "@typescript-eslint/prefer-for-of": "off", |
| 122 | + "@typescript-eslint/no-restricted-imports": "off", |
| 123 | + "@stylistic/ts/lines-between-class-members": ["error"], |
| 124 | + "@typescript-eslint/max-params": ["warn", { |
| 125 | + "max": 5 |
| 126 | + }], |
| 127 | + "@stylistic/ts/lines-around-comment": ["warn", { |
| 128 | + "allowInterfaceStart": true, |
| 129 | + "allowBlockStart": true, |
| 130 | + "allowModuleStart": true, |
| 131 | + "allowTypeStart": true, |
| 132 | + "allowObjectStart": true, |
| 133 | + "allowClassStart": true, |
| 134 | + }], |
| 135 | + "@typescript-eslint/class-methods-use-this": "off", |
| 136 | + }, |
| 137 | + }, |
| 138 | + { |
| 139 | + files: ["tests/**/*.{js,mjs,cjs,ts,mts,cts}"], |
| 140 | + plugins: { |
| 141 | + "@typescript-eslint": tseslint.plugin, |
| 142 | + "@vitest": vitest, |
| 143 | + }, |
| 144 | + languageOptions: { |
| 145 | + parser: tseslint.parser, |
| 146 | + parserOptions: { |
| 147 | + projectService: true, |
| 148 | + tsconfigRootDir: import.meta.dirname, |
| 149 | + }, |
| 150 | + globals: { |
| 151 | + ...globals.browser, |
| 152 | + ...globals.es2020, |
| 153 | + }, |
| 154 | + }, |
| 155 | + rules: { |
| 156 | + "@typescript-eslint/no-empty-function": "off", |
| 157 | + "@typescript-eslint/no-unsafe-call": "off", |
| 158 | + "@typescript-eslint/no-unsafe-member-access": "off", |
| 159 | + |
| 160 | + // Uncomment and configure these Jest/Vitest rules as needed: |
| 161 | + // "vitest/prefer-expect-assertions": "off", |
| 162 | + // "vitest/no-hooks": "off", |
| 163 | + // "vitest/prefer-called-with": "off", |
| 164 | + // "vitest/valid-title": ["error", { |
| 165 | + // mustMatch: { |
| 166 | + // it: '^should ' |
| 167 | + // } |
| 168 | + // }], |
| 169 | + // "vitest/no-restricted-matchers": [ |
| 170 | + // "error", |
| 171 | + // { |
| 172 | + // "toBeFalsy": 'Use toBe(false) instead to avoid unexpected type coercion.', |
| 173 | + // "toBeTruthy": 'Use toBe(true) instead to avoid unexpected type coercion.', |
| 174 | + // } |
| 175 | + // ], |
| 176 | + // "vitest/prefer-lowercase-title": [ |
| 177 | + // "error", |
| 178 | + // { |
| 179 | + // "ignore": ["describe"] |
| 180 | + // } |
| 181 | + // ], |
| 182 | + // "vitest/max-expects": "off" |
| 183 | + }, |
| 184 | + }, |
| 185 | +]); |
0 commit comments