Open History to see the last commit
1import { fileURLToPath } from 'node:url'
2import { tanstackConfig } from '@tanstack/oxlint-config'
3import pluginVitest from '@vitest/eslint-plugin'
4import pluginJestDom from 'eslint-plugin-jest-dom'
5import pluginJsdoc from 'eslint-plugin-jsdoc'
6import pluginTestingLibrary from 'eslint-plugin-testing-library'
7import { defineConfig } from 'oxlint'
8
9/**
10 * Oxlint ships a native `jsdoc` plugin that only covers part of
11 * 'eslint-plugin-jsdoc', so the original plugin is loaded as a JS plugin
12 * under the `jsdoc-js` alias and its recommended rules are renamed to match.
13 */
14const jsdocRecommendedRules = Object.fromEntries(
15 Object.entries(
16 pluginJsdoc.configs['flat/recommended-typescript-error'].rules ?? {},
17 ).map(([name, value]) => [name.replace(/^jsdoc\//, 'jsdoc-js/'), value]),
18)
19
20export default defineConfig({
21 extends: [tanstackConfig],
22 plugins: ['import', 'typescript', 'unicorn', 'vitest'],
23 jsPlugins: [
24 { name: 'cspell', specifier: '@cspell/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 env: tanstackConfig.env,
29 settings: {
30 vitest: { typecheck: true },
31 },
32 ignorePatterns: [
33 'examples/**',
34 'integrations/**',
35 ...tanstackConfig.ignorePatterns,
36 ],
37 rules: {
38 // Spelling
39 'cspell/spellchecker': [
40 'warn',
41 {
42 cspell: {
43 words: [
44 'Promisable', // Our public interface
45 'TSES', // @typescript-eslint package's interface
46 'codemod', // We support our codemod
47 'combinate', // Library name
48 'datatag', // Query options tagging
49 'extralight', // Our public interface
50 'jscodeshift',
51 'netinfo', // @react-native-community/netinfo package name
52 'refetched', // Query refetch operations
53 'refetches', // Query refetch operations
54 'retryer', // Our public interface
55 'solidjs', // Our target framework
56 'tabular-nums', // https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
57 'tanstack', // Our package scope
58 'todos', // Too general word to be caught as error
59 'tsqd', // Our public interface (TanStack Query Devtools shorthand)
60 'tsdown', // We use tsdown as builder
61 'typecheck', // Field of vite.config.ts
62 'vue-demi', // dependency of @tanstack/vue-query
63 'ɵkind', // Angular specific
64 'ɵproviders', // Angular specific
65 ],
66 },
67 },
68 ],
69
70 /**
71 * Disallows star exports and direct calls to deprecated imperative query
72 * methods of `QueryClient`
73 * for new tests and code
74 *
75 * Existing tests that directly test the methods from before the refactoring
76 * will be grandfathered in and allowed to continue using the deprecated methods.
77 * They should not be removed, but new tests should use the new methods instead.
78 */
79 'tanstack-query/no-restricted-syntax': [
80 'error',
81 {
82 selector: 'ExportAllDeclaration',
83 message: 'Use explicit named exports.',
84 },
85 {
86 selector:
87 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchQuery"], [callee.computed=true][callee.property.value="fetchQuery"])',
88 message: 'Use queryClient.query(options) instead.',
89 },
90 {
91 selector:
92 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchQuery"], [callee.computed=true][callee.property.value="prefetchQuery"])',
93 message:
94 'Use queryClient.query(options).catch(noop) instead if errors should be swallowed.',
95 },
96 {
97 selector:
98 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureQueryData"], [callee.computed=true][callee.property.value="ensureQueryData"])',
99 message:
100 "Use queryClient.query({ ...options, staleTime: 'static' }) instead.",
101 },
102 {
103 selector:
104 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchInfiniteQuery"], [callee.computed=true][callee.property.value="fetchInfiniteQuery"])',
105 message: 'Use queryClient.infiniteQuery(options) instead.',
106 },
107 {
108 selector:
109 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchInfiniteQuery"], [callee.computed=true][callee.property.value="prefetchInfiniteQuery"])',
110 message:
111 'Use queryClient.infiniteQuery(options).catch(noop) instead if errors should be swallowed.',
112 },
113 {
114 selector:
115 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureInfiniteQueryData"], [callee.computed=true][callee.property.value="ensureInfiniteQueryData"])',
116 message:
117 "Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead.",
118 },
119 ],
120 },
121 overrides: [
122 {
123 files: ['**/src/**/*.{ts,tsx}'],
124 excludeFiles: [
125 '**/__tests__/**',
126 '**/__testfixtures__/**',
127 '**/*.test.{ts,tsx}',
128 '**/*.test-d.{ts,tsx}',
129 ],
130 jsPlugins: [{ name: 'jsdoc-js', specifier: 'eslint-plugin-jsdoc' }],
131 rules: {
132 ...jsdocRecommendedRules,
133 'jsdoc-js/check-tag-names': [
134 'error',
135 { definedTags: ['defaultValue'] },
136 ],
137 'jsdoc-js/check-param-names': ['error', { checkDestructured: false }],
138 'jsdoc-js/require-jsdoc': [
139 'error',
140 {
141 contexts: [
142 'ExportDefaultDeclaration > ArrowFunctionExpression',
143 'ExportDefaultDeclaration > ClassDeclaration',
144 'ExportDefaultDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
145 'ExportNamedDeclaration > ClassDeclaration',
146 'ExportNamedDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
147 'ExportNamedDeclaration > TSInterfaceDeclaration',
148 'ExportNamedDeclaration > TSInterfaceDeclaration > TSInterfaceBody > TSPropertySignature',
149 'ExportNamedDeclaration > TSTypeAliasDeclaration',
150 'ExportNamedDeclaration > TSTypeAliasDeclaration > TSTypeLiteral > TSPropertySignature',
151 'ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression',
152 ],
153 },
154 ],
155 'jsdoc-js/require-param': ['error', { checkDestructured: false }],
156 'jsdoc-js/check-template-names': 'error',
157 'jsdoc-js/informative-docs': 'error',
158 'jsdoc-js/match-description': 'error',
159 'jsdoc-js/no-bad-blocks': 'error',
160 'jsdoc-js/no-blank-block-descriptions': 'error',
161 'jsdoc-js/no-blank-blocks': 'error',
162 'jsdoc-js/require-asterisk-prefix': 'error',
163 'jsdoc-js/require-description': 'error',
164 'jsdoc-js/require-hyphen-before-param-description': 'error',
165 'jsdoc-js/require-next-description': 'error',
166 'jsdoc-js/require-template-description': 'error',
167 'jsdoc-js/require-throws': 'error',
168 'jsdoc-js/require-throws-description': 'error',
169 'jsdoc-js/require-yields-description': 'error',
170 'jsdoc-js/sort-tags': 'error',
171 },
172 },
173 {
174 files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
175 jsPlugins: [
176 // Unlike the native rule, also checks `expectTypeOf` calls
177 { name: 'vitest-js', specifier: '@vitest/eslint-plugin' },
178 { name: 'jest-dom', specifier: 'eslint-plugin-jest-dom' },
179 { name: 'testing-library', specifier: 'eslint-plugin-testing-library' },
180 ],
181 rules: {
182 ...pluginVitest.configs.recommended.rules,
183 ...pluginJestDom.configs['flat/recommended'].rules,
184 // `toHaveTextContent` matches substrings, so exact `textContent` checks stay as `toBe`
185 'jest-dom/prefer-to-have-text-content': 'off',
186 ...pluginTestingLibrary.configs['flat/dom'].rules,
187 'testing-library/no-debugging-utils': 'error',
188 'testing-library/no-dom-import': 'error',
189 'testing-library/no-manual-cleanup': 'error',
190 'testing-library/no-render-in-lifecycle': 'error',
191 // Tests name the render result `rendered` and query through it
192 'testing-library/prefer-screen-queries': 'off',
193 'vitest/consistent-each-for': [
194 'error',
195 { describe: 'each', it: 'each' },
196 ],
197 'vitest/consistent-test-filename': 'error',
198 'vitest/consistent-test-it': [
199 'error',
200 { fn: 'it', withinDescribe: 'it' },
201 ],
202 'vitest/consistent-vitest-vi': 'error',
203 'vitest/hoisted-apis-on-top': 'error',
204 'vitest/max-nested-describe': 'error',
205 'vitest/no-alias-methods': 'error',
206 'vitest/no-conditional-tests': 'error',
207 'vitest/no-duplicate-hooks': 'error',
208 'vitest/no-large-snapshots': 'error',
209 'vitest/no-test-prefixes': 'error',
210 'vitest/no-test-return-statement': 'error',
211 'vitest/prefer-called-times': 'error',
212 'vitest/prefer-called-with': 'error',
213 'vitest/prefer-comparison-matcher': 'error',
214 'vitest/prefer-each': 'error',
215 'vitest/prefer-equality-matcher': 'error',
216 'vitest/prefer-expect-resolves': 'error',
217 'vitest/prefer-expect-type-of': 'error',
218 'vitest/prefer-hooks-in-order': 'error',
219 'vitest/prefer-hooks-on-top': 'error',
220 'vitest/prefer-import-in-mock': 'error',
221 'vitest/prefer-importing-vitest-globals': 'error',
222 'vitest/prefer-lowercase-title': ['error', { ignore: ['describe'] }],
223 'vitest/prefer-mock-promise-shorthand': 'error',
224 'vitest/prefer-mock-return-shorthand': 'error',
225 'vitest/prefer-snapshot-hint': 'error',
226 'vitest/prefer-spy-on': 'error',
227 'vitest/prefer-strict-boolean-matchers': 'error',
228 'vitest/prefer-strict-equal': 'error',
229 'vitest/prefer-to-be': 'error',
230 'vitest/prefer-to-be-object': 'error',
231 'vitest/prefer-to-contain': 'error',
232 'vitest/prefer-to-have-been-called-times': 'error',
233 'vitest/prefer-to-have-length': 'error',
234 'vitest/prefer-todo': 'error',
235 'vitest/require-awaited-expect-poll': 'error',
236 'vitest/require-hook': 'error',
237 'vitest/require-mock-type-parameters': 'error',
238 'vitest/require-to-throw-message': 'error',
239 'vitest/require-top-level-describe': 'error',
240 'vitest/valid-expect': 'off',
241 'vitest-js/no-conditional-in-test': 'error',
242 'vitest-js/padding-around-after-all-blocks': 'error',
243 'vitest-js/padding-around-after-each-blocks': 'error',
244 'vitest-js/padding-around-before-all-blocks': 'error',
245 'vitest-js/padding-around-before-each-blocks': 'error',
246 'vitest-js/padding-around-describe-blocks': 'error',
247 'vitest-js/padding-around-test-blocks': 'error',
248 'vitest-js/prefer-vi-mocked': 'error',
249 'vitest-js/valid-expect': 'error',
250 },
251 },
252 {
253 files: ['**/*.test-d.ts*'],
254 rules: {
255 // Type tests narrow results with `if` to check the type of each state
256 'vitest-js/no-conditional-in-test': 'off',
257 },
258 },
259 ],
260})
261
262/**
263 * Native Oxlint equivalent of 'eslint-config-preact', applied on top of the root config.
264 *
265 * Not ported because Oxlint does not implement them: `no-dupe-args`, `no-undef`,
266 * `no-undef-init`, `strict`, `react/jsx-no-bind`, `react/jsx-uses-react`,
267 * `react/jsx-uses-vars`, `react/no-deprecated`, `react/prefer-stateless-function`
268 * and `react/require-render-return`.
269 */
270export const preactConfig = defineConfig({
271 plugins: ['import', 'typescript', 'unicorn', 'vitest', 'react'],
272 settings: {
273 react: { version: '16.0' },
274 },
275 rules: {
276 // 'eslint:recommended'
277 'constructor-super': 'error',
278 'getter-return': 'error',
279 'no-case-declarations': 'error',
280 'no-const-assign': 'error',
281 'no-dupe-class-members': 'error',
282 'no-dupe-keys': 'error',
283 'no-func-assign': 'error',
284 'no-new-native-nonconstructor': 'error',
285 'no-obj-calls': 'error',
286 'no-prototype-builtins': 'error',
287 'no-setter-return': 'error',
288 'no-this-before-super': 'error',
289 'no-unexpected-multiline': 'error',
290 'no-unreachable': 'error',
291 'no-unsafe-negation': 'error',
292
293 // Preact / JSX
294 'react/display-name': ['warn', { ignoreTranspilerName: false }],
295 'react/jsx-key': ['error', { checkFragmentShorthand: true }],
296 'react/jsx-no-comment-textnodes': 'error',
297 'react/jsx-no-duplicate-props': 'error',
298 'react/jsx-no-target-blank': 'error',
299 'react/jsx-no-undef': 'error',
300 'react/no-danger': 'warn',
301 'react/no-did-mount-set-state': 'error',
302 'react/no-did-update-set-state': 'error',
303 'react/no-find-dom-node': 'error',
304 'react/no-is-mounted': 'error',
305 'react/no-string-refs': 'error',
306 'react/prefer-es6-class': 'error',
307 'react/self-closing-comp': 'error',
308
309 // Hooks
310 'react/rules-of-hooks': 'error',
311 'react/exhaustive-deps': 'warn',
312
313 // General JavaScript error avoidance
314 'no-caller': 'error',
315 'no-else-return': 'warn',
316 'no-empty-pattern': 'off',
317 'no-iterator': 'error',
318 'no-lonely-if': 'error',
319 'no-multi-str': 'warn',
320 'no-new-wrappers': 'error',
321 'no-proto': 'error',
322 'no-shadow': 'off',
323 'no-unneeded-ternary': 'error',
324 'no-useless-call': 'warn',
325 'no-useless-computed-key': 'warn',
326 'no-useless-concat': 'warn',
327 'no-useless-constructor': 'warn',
328 'no-useless-escape': 'warn',
329 'no-useless-rename': 'warn',
330 'no-var': 'warn',
331
332 // General JavaScript style
333 'object-shorthand': 'warn',
334 'prefer-arrow-callback': 'warn',
335 'prefer-rest-params': 'warn',
336 'prefer-spread': 'warn',
337 'prefer-template': 'warn',
338 radix: 'warn',
339 'unicode-bom': 'error',
340 },
341})
342
343/**
344 * Native Oxlint equivalent of 'eslint-plugin-vue' 'flat/recommended', applied on top of the root config.
345 *
346 * Only the rules Oxlint implements are ported. Template rules are not, because Oxlint only lints
347 * the `<script>` blocks of `.vue` files.
348 */
349export const vueConfig = defineConfig({
350 plugins: ['import', 'typescript', 'unicorn', 'vitest', 'vue'],
351 rules: {
352 'vue/component-definition-name-casing': 'warn',
353 'vue/no-arrow-functions-in-watch': 'error',
354 'vue/no-async-in-computed-properties': 'error',
355 'vue/no-computed-properties-in-data': 'error',
356 'vue/no-deprecated-data-object-declaration': 'error',
357 'vue/no-deprecated-delete-set': 'error',
358 'vue/no-deprecated-destroyed-lifecycle': 'error',
359 'vue/no-deprecated-events-api': 'error',
360 'vue/no-deprecated-model-definition': 'error',
361 'vue/no-deprecated-props-default-this': 'error',
362 'vue/no-deprecated-vue-config-keycodes': 'error',
363 'vue/no-dupe-keys': 'error',
364 'vue/no-export-in-script-setup': 'error',
365 'vue/no-expose-after-await': 'error',
366 'vue/no-lifecycle-after-await': 'error',
367 'vue/no-multiple-slot-args': 'warn',
368 'vue/no-required-prop-with-default': 'warn',
369 'vue/no-reserved-component-names': 'error',
370 'vue/no-reserved-keys': 'error',
371 'vue/no-reserved-props': 'error',
372 'vue/no-shared-component-data': 'error',
373 'vue/no-side-effects-in-computed-properties': 'error',
374 'vue/no-watch-after-await': 'error',
375 'vue/prefer-import-from-vue': 'error',
376 'vue/prop-name-casing': 'warn',
377 'vue/require-default-prop': 'warn',
378 'vue/require-prop-type-constructor': 'error',
379 'vue/require-prop-types': 'warn',
380 'vue/require-render-return': 'error',
381 'vue/require-slots-as-functions': 'error',
382 'vue/return-in-computed-property': 'error',
383 'vue/return-in-emits-validator': 'error',
384 'vue/valid-define-emits': 'error',
385 'vue/valid-define-options': 'error',
386 'vue/valid-define-props': 'error',
387 'vue/valid-next-tick': 'error',
388 },
389})