Open History to see the last commit
1import { fileURLToPath } from 'node:url'
2import pluginVitest from '@vitest/eslint-plugin'
3import pluginJestDom from 'eslint-plugin-jest-dom'
4import pluginJsdoc from 'eslint-plugin-jsdoc'
5import pluginTestingLibrary from 'eslint-plugin-testing-library'
6import { defineConfig } from 'oxlint'
7
8/**
9 * Oxlint ships a native `jsdoc` plugin that only covers part of
10 * 'eslint-plugin-jsdoc', so the original plugin is loaded as a JS plugin
11 * under the `jsdoc-js` alias and its recommended rules are renamed to match.
12 */
13const jsdocRecommendedRules = Object.fromEntries(
14 Object.entries(
15 pluginJsdoc.configs['flat/recommended-typescript-error'].rules ?? {},
16 ).map(([name, value]) => [name.replace(/^jsdoc\//, 'jsdoc-js/'), value]),
17)
18
19export default defineConfig({
20 plugins: ['import', 'typescript', 'unicorn', 'vitest'],
21 jsPlugins: [
22 { name: 'import-js', specifier: 'eslint-plugin-import-x' },
23 { name: 'cspell', specifier: '@cspell/eslint-plugin' },
24 '@stylistic/eslint-plugin',
25 // Absolute path so that package configs can extend this config
26 fileURLToPath(new URL('./scripts/oxlint/plugin.ts', import.meta.url)),
27 ],
28 categories: {
29 correctness: 'off',
30 },
31 options: {
32 typeAware: true,
33 },
34 env: {
35 browser: true,
36 es2020: true,
37 },
38 settings: {
39 vitest: { typecheck: true },
40 },
41 ignorePatterns: [
42 'examples/**',
43 'integrations/**',
44 '**/.nx/**',
45 '**/.svelte-kit/**',
46 '**/build/**',
47 '**/coverage/**',
48 '**/dist/**',
49 '**/snap/**',
50 '**/vite.config.*.timestamp-*.*',
51 ],
52 rules: {
53 // JavaScript
54 'for-direction': 'error',
55 'no-async-promise-executor': 'error',
56 'no-class-assign': 'error',
57 'no-compare-neg-zero': 'error',
58 'no-cond-assign': 'error',
59 'no-constant-binary-expression': 'error',
60 'no-constant-condition': 'error',
61 'no-control-regex': 'error',
62 'no-debugger': 'error',
63 'no-delete-var': 'error',
64 'no-dupe-else-if': 'error',
65 'no-duplicate-case': 'error',
66 'no-empty-character-class': 'error',
67 'no-empty-pattern': 'error',
68 'no-empty-static-block': 'error',
69 'no-ex-assign': 'error',
70 'no-extra-boolean-cast': 'error',
71 'no-fallthrough': 'error',
72 'no-global-assign': 'error',
73 'no-invalid-regexp': 'error',
74 'no-irregular-whitespace': 'error',
75 'no-loss-of-precision': 'error',
76 'no-misleading-character-class': 'error',
77 'no-nonoctal-decimal-escape': 'error',
78 'no-regex-spaces': 'error',
79 'no-self-assign': 'error',
80 'no-shadow': 'warn',
81 'no-shadow-restricted-names': 'error',
82 'no-sparse-arrays': 'error',
83 'no-unsafe-finally': 'error',
84 'no-unsafe-optional-chaining': 'error',
85 'no-unused-labels': 'error',
86 'no-unused-private-class-members': 'error',
87 'no-useless-backreference': 'error',
88 'no-useless-catch': 'error',
89 'no-useless-escape': 'error',
90 'no-var': 'error',
91 'no-with': 'error',
92 'require-yield': 'error',
93 'sort-imports': ['error', { ignoreDeclarationSort: true }],
94 'use-isnan': 'error',
95 'valid-typeof': 'error',
96
97 // Imports
98 'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
99 'import/first': 'error',
100 'import/newline-after-import': 'error',
101 'import/no-commonjs': 'error',
102 'import/no-duplicates': 'error',
103 'import-js/order': [
104 'error',
105 {
106 groups: [
107 'builtin',
108 'external',
109 'internal',
110 'parent',
111 'sibling',
112 'index',
113 'object',
114 'type',
115 ],
116 },
117 ],
118
119 // TypeScript
120 'typescript/array-type': [
121 'error',
122 { default: 'generic', readonly: 'generic' },
123 ],
124 'typescript/ban-ts-comment': [
125 'error',
126 { 'ts-expect-error': false, 'ts-ignore': 'allow-with-description' },
127 ],
128 'typescript/consistent-type-imports': ['error', { prefer: 'type-imports' }],
129 'typescript/method-signature-style': ['error', 'property'],
130 'typescript/no-duplicate-enum-values': 'error',
131 'typescript/no-extra-non-null-assertion': 'error',
132 'typescript/no-for-in-array': 'error',
133 'typescript/no-inferrable-types': ['error', { ignoreParameters: true }],
134 'typescript/no-misused-new': 'error',
135 'typescript/no-namespace': 'error',
136 'typescript/no-non-null-asserted-optional-chain': 'error',
137 'typescript/no-unnecessary-condition': 'error',
138 'typescript/no-unnecessary-type-assertion': 'error',
139 'typescript/no-wrapper-object-types': 'error',
140 'typescript/prefer-as-const': 'error',
141 'typescript/prefer-for-of': 'warn',
142 'typescript/require-await': 'warn',
143 'typescript/triple-slash-reference': 'error',
144 'tanstack-query/type-parameter-naming': 'error',
145
146 // Node
147 'unicorn/prefer-node-protocol': 'error',
148
149 // Stylistic
150 '@stylistic/spaced-comment': 'error',
151
152 // Spelling
153 'cspell/spellchecker': [
154 'warn',
155 {
156 cspell: {
157 words: [
158 'Promisable', // Our public interface
159 'TSES', // @typescript-eslint package's interface
160 'codemod', // We support our codemod
161 'combinate', // Library name
162 'datatag', // Query options tagging
163 'extralight', // Our public interface
164 'jscodeshift',
165 'netinfo', // @react-native-community/netinfo package name
166 'refetched', // Query refetch operations
167 'refetches', // Query refetch operations
168 'retryer', // Our public interface
169 'seroval', // Solid serialization library used in SSR
170 'solidjs', // Our target framework
171 'tabular-nums', // https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
172 'tanstack', // Our package scope
173 'todos', // Too general word to be caught as error
174 'tsqd', // Our public interface (TanStack Query Devtools shorthand)
175 'tsdown', // We use tsdown as builder
176 'typecheck', // Field of vite.config.ts
177 'vue-demi', // dependency of @tanstack/vue-query
178 'ɵkind', // Angular specific
179 'ɵproviders', // Angular specific
180 ],
181 },
182 },
183 ],
184
185 /**
186 * Disallows star exports and direct calls to deprecated imperative query
187 * methods of `QueryClient`
188 * for new tests and code
189 *
190 * Existing tests that directly test the methods from before the refactoring
191 * will be grandfathered in and allowed to continue using the deprecated methods.
192 * They should not be removed, but new tests should use the new methods instead.
193 */
194 'tanstack-query/no-restricted-syntax': [
195 'error',
196 {
197 selector: 'ExportAllDeclaration',
198 message: 'Use explicit named exports.',
199 },
200 {
201 selector:
202 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchQuery"], [callee.computed=true][callee.property.value="fetchQuery"])',
203 message: 'Use queryClient.query(options) instead.',
204 },
205 {
206 selector:
207 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchQuery"], [callee.computed=true][callee.property.value="prefetchQuery"])',
208 message:
209 'Use queryClient.query(options).catch(noop) instead if errors should be swallowed.',
210 },
211 {
212 selector:
213 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureQueryData"], [callee.computed=true][callee.property.value="ensureQueryData"])',
214 message:
215 "Use queryClient.query({ ...options, staleTime: 'static' }) instead.",
216 },
217 {
218 selector:
219 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchInfiniteQuery"], [callee.computed=true][callee.property.value="fetchInfiniteQuery"])',
220 message: 'Use queryClient.infiniteQuery(options) instead.',
221 },
222 {
223 selector:
224 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchInfiniteQuery"], [callee.computed=true][callee.property.value="prefetchInfiniteQuery"])',
225 message:
226 'Use queryClient.infiniteQuery(options).catch(noop) instead if errors should be swallowed.',
227 },
228 {
229 selector:
230 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureInfiniteQueryData"], [callee.computed=true][callee.property.value="ensureInfiniteQueryData"])',
231 message:
232 "Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead.",
233 },
234 ],
235 },
236 overrides: [
237 {
238 files: ['**/src/**/*.{ts,tsx}'],
239 excludeFiles: [
240 '**/__tests__/**',
241 '**/__testfixtures__/**',
242 '**/*.test.{ts,tsx}',
243 '**/*.test-d.{ts,tsx}',
244 ],
245 jsPlugins: [{ name: 'jsdoc-js', specifier: 'eslint-plugin-jsdoc' }],
246 rules: {
247 ...jsdocRecommendedRules,
248 'jsdoc-js/check-tag-names': [
249 'error',
250 { definedTags: ['defaultValue'] },
251 ],
252 'jsdoc-js/check-param-names': ['error', { checkDestructured: false }],
253 'jsdoc-js/require-jsdoc': [
254 'error',
255 {
256 contexts: [
257 'ExportDefaultDeclaration > ArrowFunctionExpression',
258 'ExportDefaultDeclaration > ClassDeclaration',
259 'ExportDefaultDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
260 'ExportNamedDeclaration > ClassDeclaration',
261 'ExportNamedDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
262 'ExportNamedDeclaration > TSInterfaceDeclaration',
263 'ExportNamedDeclaration > TSInterfaceDeclaration > TSInterfaceBody > TSPropertySignature',
264 'ExportNamedDeclaration > TSTypeAliasDeclaration',
265 'ExportNamedDeclaration > TSTypeAliasDeclaration > TSTypeLiteral > TSPropertySignature',
266 'ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression',
267 ],
268 },
269 ],
270 'jsdoc-js/require-param': ['error', { checkDestructured: false }],
271 'jsdoc-js/check-template-names': 'error',
272 'jsdoc-js/informative-docs': 'error',
273 'jsdoc-js/match-description': 'error',
274 'jsdoc-js/no-bad-blocks': 'error',
275 'jsdoc-js/no-blank-block-descriptions': 'error',
276 'jsdoc-js/no-blank-blocks': 'error',
277 'jsdoc-js/require-asterisk-prefix': 'error',
278 'jsdoc-js/require-description': 'error',
279 'jsdoc-js/require-hyphen-before-param-description': 'error',
280 'jsdoc-js/require-next-description': 'error',
281 'jsdoc-js/require-template-description': 'error',
282 'jsdoc-js/require-throws': 'error',
283 'jsdoc-js/require-throws-description': 'error',
284 'jsdoc-js/require-yields-description': 'error',
285 'jsdoc-js/sort-tags': 'error',
286 },
287 },
288 {
289 files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
290 jsPlugins: [
291 // Unlike the native rule, also checks `expectTypeOf` calls
292 { name: 'vitest-js', specifier: '@vitest/eslint-plugin' },
293 { name: 'jest-dom', specifier: 'eslint-plugin-jest-dom' },
294 { name: 'testing-library', specifier: 'eslint-plugin-testing-library' },
295 ],
296 rules: {
297 ...pluginVitest.configs.recommended.rules,
298 ...pluginJestDom.configs['flat/recommended'].rules,
299 // `toHaveTextContent` matches substrings, so exact `textContent` checks stay as `toBe`
300 'jest-dom/prefer-to-have-text-content': 'off',
301 ...pluginTestingLibrary.configs['flat/dom'].rules,
302 'testing-library/no-debugging-utils': 'error',
303 'testing-library/no-dom-import': 'error',
304 'testing-library/no-manual-cleanup': 'error',
305 'testing-library/no-render-in-lifecycle': 'error',
306 // Tests name the render result `rendered` and query through it
307 'testing-library/prefer-screen-queries': 'off',
308 'vitest/consistent-each-for': [
309 'error',
310 { describe: 'each', it: 'each' },
311 ],
312 'vitest/consistent-test-filename': 'error',
313 'vitest/consistent-test-it': [
314 'error',
315 { fn: 'it', withinDescribe: 'it' },
316 ],
317 'vitest/consistent-vitest-vi': 'error',
318 'vitest/hoisted-apis-on-top': 'error',
319 'vitest/max-nested-describe': 'error',
320 'vitest/no-alias-methods': 'error',
321 'vitest/no-conditional-tests': 'error',
322 'vitest/no-duplicate-hooks': 'error',
323 'vitest/no-large-snapshots': 'error',
324 'vitest/no-test-prefixes': 'error',
325 'vitest/no-test-return-statement': 'error',
326 'vitest/prefer-called-times': 'error',
327 'vitest/prefer-called-with': 'error',
328 'vitest/prefer-comparison-matcher': 'error',
329 'vitest/prefer-each': 'error',
330 'vitest/prefer-equality-matcher': 'error',
331 'vitest/prefer-expect-resolves': 'error',
332 'vitest/prefer-expect-type-of': 'error',
333 'vitest/prefer-hooks-in-order': 'error',
334 'vitest/prefer-hooks-on-top': 'error',
335 'vitest/prefer-import-in-mock': 'error',
336 'vitest/prefer-importing-vitest-globals': 'error',
337 'vitest/prefer-lowercase-title': ['error', { ignore: ['describe'] }],
338 'vitest/prefer-mock-promise-shorthand': 'error',
339 'vitest/prefer-mock-return-shorthand': 'error',
340 'vitest/prefer-snapshot-hint': 'error',
341 'vitest/prefer-spy-on': 'error',
342 'vitest/prefer-strict-boolean-matchers': 'error',
343 'vitest/prefer-strict-equal': 'error',
344 'vitest/prefer-to-be': 'error',
345 'vitest/prefer-to-be-object': 'error',
346 'vitest/prefer-to-contain': 'error',
347 'vitest/prefer-to-have-been-called-times': 'error',
348 'vitest/prefer-to-have-length': 'error',
349 'vitest/prefer-todo': 'error',
350 'vitest/require-awaited-expect-poll': 'error',
351 'vitest/require-hook': 'error',
352 'vitest/require-mock-type-parameters': 'error',
353 'vitest/require-to-throw-message': 'error',
354 'vitest/require-top-level-describe': 'error',
355 'vitest/valid-expect': 'off',
356 'vitest-js/no-conditional-in-test': 'error',
357 'vitest-js/padding-around-after-all-blocks': 'error',
358 'vitest-js/padding-around-after-each-blocks': 'error',
359 'vitest-js/padding-around-before-all-blocks': 'error',
360 'vitest-js/padding-around-before-each-blocks': 'error',
361 'vitest-js/padding-around-describe-blocks': 'error',
362 'vitest-js/padding-around-test-blocks': 'error',
363 'vitest-js/prefer-vi-mocked': 'error',
364 'vitest-js/valid-expect': 'error',
365 },
366 },
367 {
368 files: ['**/*.test-d.ts*'],
369 rules: {
370 // Type tests narrow results with `if` to check the type of each state
371 'vitest-js/no-conditional-in-test': 'off',
372 },
373 },
374 ],
375})
376
377/**
378 * Native Oxlint equivalent of 'eslint-config-preact', applied on top of the root config.
379 *
380 * Not ported because Oxlint does not implement them: `no-dupe-args`, `no-undef`,
381 * `no-undef-init`, `strict`, `react/jsx-no-bind`, `react/jsx-uses-react`,
382 * `react/jsx-uses-vars`, `react/no-deprecated`, `react/prefer-stateless-function`
383 * and `react/require-render-return`.
384 */
385export const preactConfig = defineConfig({
386 plugins: ['import', 'typescript', 'unicorn', 'vitest', 'react'],
387 settings: {
388 react: { version: '16.0' },
389 },
390 rules: {
391 // 'eslint:recommended'
392 'constructor-super': 'error',
393 'getter-return': 'error',
394 'no-case-declarations': 'error',
395 'no-const-assign': 'error',
396 'no-dupe-class-members': 'error',
397 'no-dupe-keys': 'error',
398 'no-func-assign': 'error',
399 'no-new-native-nonconstructor': 'error',
400 'no-obj-calls': 'error',
401 'no-prototype-builtins': 'error',
402 'no-setter-return': 'error',
403 'no-this-before-super': 'error',
404 'no-unexpected-multiline': 'error',
405 'no-unreachable': 'error',
406 'no-unsafe-negation': 'error',
407
408 // Preact / JSX
409 'react/display-name': ['warn', { ignoreTranspilerName: false }],
410 'react/jsx-key': ['error', { checkFragmentShorthand: true }],
411 'react/jsx-no-comment-textnodes': 'error',
412 'react/jsx-no-duplicate-props': 'error',
413 'react/jsx-no-target-blank': 'error',
414 'react/jsx-no-undef': 'error',
415 'react/no-danger': 'warn',
416 'react/no-did-mount-set-state': 'error',
417 'react/no-did-update-set-state': 'error',
418 'react/no-find-dom-node': 'error',
419 'react/no-is-mounted': 'error',
420 'react/no-string-refs': 'error',
421 'react/prefer-es6-class': 'error',
422 'react/self-closing-comp': 'error',
423
424 // Hooks
425 'react/rules-of-hooks': 'error',
426 'react/exhaustive-deps': 'warn',
427
428 // General JavaScript error avoidance
429 'no-caller': 'error',
430 'no-else-return': 'warn',
431 'no-empty-pattern': 'off',
432 'no-iterator': 'error',
433 'no-lonely-if': 'error',
434 'no-multi-str': 'warn',
435 'no-new-wrappers': 'error',
436 'no-proto': 'error',
437 'no-shadow': 'off',
438 'no-unneeded-ternary': 'error',
439 'no-useless-call': 'warn',
440 'no-useless-computed-key': 'warn',
441 'no-useless-concat': 'warn',
442 'no-useless-constructor': 'warn',
443 'no-useless-escape': 'warn',
444 'no-useless-rename': 'warn',
445 'no-var': 'warn',
446
447 // General JavaScript style
448 'object-shorthand': 'warn',
449 'prefer-arrow-callback': 'warn',
450 'prefer-rest-params': 'warn',
451 'prefer-spread': 'warn',
452 'prefer-template': 'warn',
453 radix: 'warn',
454 'unicode-bom': 'error',
455 },
456})
457
458/**
459 * Native Oxlint equivalent of 'eslint-plugin-vue' 'flat/recommended', applied on top of the root config.
460 *
461 * Only the rules Oxlint implements are ported. Template rules are not, because Oxlint only lints
462 * the `<script>` blocks of `.vue` files.
463 */
464export const vueConfig = defineConfig({
465 plugins: ['import', 'typescript', 'unicorn', 'vitest', 'vue'],
466 rules: {
467 'vue/component-definition-name-casing': 'warn',
468 'vue/no-arrow-functions-in-watch': 'error',
469 'vue/no-async-in-computed-properties': 'error',
470 'vue/no-computed-properties-in-data': 'error',
471 'vue/no-deprecated-data-object-declaration': 'error',
472 'vue/no-deprecated-delete-set': 'error',
473 'vue/no-deprecated-destroyed-lifecycle': 'error',
474 'vue/no-deprecated-events-api': 'error',
475 'vue/no-deprecated-model-definition': 'error',
476 'vue/no-deprecated-props-default-this': 'error',
477 'vue/no-deprecated-vue-config-keycodes': 'error',
478 'vue/no-dupe-keys': 'error',
479 'vue/no-export-in-script-setup': 'error',
480 'vue/no-expose-after-await': 'error',
481 'vue/no-lifecycle-after-await': 'error',
482 'vue/no-multiple-slot-args': 'warn',
483 'vue/no-required-prop-with-default': 'warn',
484 'vue/no-reserved-component-names': 'error',
485 'vue/no-reserved-keys': 'error',
486 'vue/no-reserved-props': 'error',
487 'vue/no-shared-component-data': 'error',
488 'vue/no-side-effects-in-computed-properties': 'error',
489 'vue/no-watch-after-await': 'error',
490 'vue/prefer-import-from-vue': 'error',
491 'vue/prop-name-casing': 'warn',
492 'vue/require-default-prop': 'warn',
493 'vue/require-prop-type-constructor': 'error',
494 'vue/require-prop-types': 'warn',
495 'vue/require-render-return': 'error',
496 'vue/require-slots-as-functions': 'error',
497 'vue/return-in-computed-property': 'error',
498 'vue/return-in-emits-validator': 'error',
499 'vue/valid-define-emits': 'error',
500 'vue/valid-define-options': 'error',
501 'vue/valid-define-props': 'error',
502 'vue/valid-next-tick': 'error',
503 },
504})