Skip to content
Source
Sign inSign up
TanStack/query
Open History to see the last commit

oxlint.config.ts

381 lines13.8 KB

1import { fileURLToPath } from 'node:url'
2import pluginVitest from '@vitest/eslint-plugin'
3import pluginJsdoc from 'eslint-plugin-jsdoc'
4import { defineConfig } from 'oxlint'
5​
6/**
7 * Oxlint ships a native `jsdoc` plugin that only covers part of
8 * 'eslint-plugin-jsdoc', so the original plugin is loaded as a JS plugin
9 * under the `jsdoc-js` alias and its recommended rules are renamed to match.
10 */
11const jsdocRecommendedRules = Object.fromEntries(
12 Object.entries(
13 pluginJsdoc.configs['flat/recommended-typescript-error'].rules ?? {},
14 ).map(([name, value]) => [name.replace(/^jsdoc\//, 'jsdoc-js/'), value]),
16​
17export default defineConfig({
18 plugins: ['import', 'typescript', 'unicorn', 'vitest'],
19 jsPlugins: [
20 { name: 'import-js', specifier: 'eslint-plugin-import-x' },
21 { name: 'cspell', specifier: '@cspell/eslint-plugin' },
22 '@stylistic/eslint-plugin',
23 // Absolute path so that package configs can extend this config
24 fileURLToPath(new URL('./scripts/oxlint/plugin.ts', import.meta.url)),
25 ],
26 categories: {
27 correctness: 'off',
28 },
29 options: {
30 typeAware: true,
31 },
32 env: {
33 browser: true,
34 es2020: true,
35 },
36 settings: {
37 vitest: { typecheck: true },
38 },
39 ignorePatterns: [
40 'examples/**',
41 'integrations/**',
42 '**/.nx/**',
43 '**/.svelte-kit/**',
44 '**/build/**',
45 '**/coverage/**',
46 '**/dist/**',
47 '**/snap/**',
48 '**/vite.config.*.timestamp-*.*',
49 ],
50 rules: {
51 // JavaScript
52 'for-direction': 'error',
53 'no-async-promise-executor': 'error',
54 'no-class-assign': 'error',
55 'no-compare-neg-zero': 'error',
56 'no-cond-assign': 'error',
57 'no-constant-binary-expression': 'error',
58 'no-constant-condition': 'error',
59 'no-control-regex': 'error',
60 'no-debugger': 'error',
61 'no-delete-var': 'error',
62 'no-dupe-else-if': 'error',
63 'no-duplicate-case': 'error',
64 'no-empty-character-class': 'error',
65 'no-empty-pattern': 'error',
66 'no-empty-static-block': 'error',
67 'no-ex-assign': 'error',
68 'no-extra-boolean-cast': 'error',
69 'no-fallthrough': 'error',
70 'no-global-assign': 'error',
71 'no-invalid-regexp': 'error',
72 'no-irregular-whitespace': 'error',
73 'no-loss-of-precision': 'error',
74 'no-misleading-character-class': 'error',
75 'no-nonoctal-decimal-escape': 'error',
76 'no-regex-spaces': 'error',
77 'no-self-assign': 'error',
78 'no-shadow': 'warn',
79 'no-shadow-restricted-names': 'error',
80 'no-sparse-arrays': 'error',
81 'no-unsafe-finally': 'error',
82 'no-unsafe-optional-chaining': 'error',
83 'no-unused-labels': 'error',
84 'no-unused-private-class-members': 'error',
85 'no-useless-backreference': 'error',
86 'no-useless-catch': 'error',
87 'no-useless-escape': 'error',
88 'no-var': 'error',
89 'no-with': 'error',
90 'require-yield': 'error',
91 'sort-imports': ['error', { ignoreDeclarationSort: true }],
92 'use-isnan': 'error',
93 'valid-typeof': 'error',
94​
95 // Imports
96 'import/consistent-type-specifier-style': ['error', 'prefer-top-level'],
97 'import/first': 'error',
98 'import/newline-after-import': 'error',
99 'import/no-commonjs': 'error',
100 'import/no-duplicates': 'error',
101 'import-js/order': [
102 'error',
103 {
104 groups: [
105 'builtin',
106 'external',
107 'internal',
108 'parent',
109 'sibling',
110 'index',
111 'object',
112 'type',
113 ],
114 },
115 ],
116​
117 // TypeScript
118 'typescript/array-type': [
119 'error',
120 { default: 'generic', readonly: 'generic' },
121 ],
122 'typescript/ban-ts-comment': [
123 'error',
124 { 'ts-expect-error': false, 'ts-ignore': 'allow-with-description' },
125 ],
126 'typescript/consistent-type-imports': ['error', { prefer: 'type-imports' }],
127 'typescript/method-signature-style': ['error', 'property'],
128 'typescript/no-duplicate-enum-values': 'error',
129 'typescript/no-extra-non-null-assertion': 'error',
130 'typescript/no-for-in-array': 'error',
131 'typescript/no-inferrable-types': ['error', { ignoreParameters: true }],
132 'typescript/no-misused-new': 'error',
133 'typescript/no-namespace': 'error',
134 'typescript/no-non-null-asserted-optional-chain': 'error',
135 'typescript/no-unnecessary-condition': 'error',
136 'typescript/no-unnecessary-type-assertion': 'error',
137 'typescript/no-wrapper-object-types': 'error',
138 'typescript/prefer-as-const': 'error',
139 'typescript/prefer-for-of': 'warn',
140 'typescript/require-await': 'warn',
141 'typescript/triple-slash-reference': 'error',
142 'tanstack-query/type-parameter-naming': 'error',
143​
144 // Node
145 'unicorn/prefer-node-protocol': 'error',
146​
147 // Stylistic
148 '@stylistic/spaced-comment': 'error',
149​
150 // Spelling
151 'cspell/spellchecker': [
152 'warn',
153 {
154 cspell: {
155 words: [
156 'Promisable', // Our public interface
157 'TSES', // @typescript-eslint package's interface
158 'codemod', // We support our codemod
159 'combinate', // Library name
160 'datatag', // Query options tagging
161 'extralight', // Our public interface
162 'jscodeshift',
163 'refetched', // Query refetch operations
164 'refetches', // Query refetch operations
165 'retryer', // Our public interface
166 'solidjs', // Our target framework
167 'tabular-nums', // https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
168 'tanstack', // Our package scope
169 'todos', // Too general word to be caught as error
170 'tsqd', // Our public interface (TanStack Query Devtools shorthand)
171 'tsdown', // We use tsdown as builder
172 'typecheck', // Field of vite.config.ts
173 'vue-demi', // dependency of @tanstack/vue-query
174 'ɵkind', // Angular specific
175 'ɵproviders', // Angular specific
176 ],
177 },
178 },
179 ],
180​
181 /**
182 * Disallows direct calls to deprecated imperative query methods of `QueryClient`
183 * for new tests and code
184 *
185 * Existing tests that directly test the methods from before the refactoring
186 * will be grandfathered in and allowed to continue using the deprecated methods.
187 * They should not be removed, but new tests should use the new methods instead.
188 */
189 'tanstack-query/no-restricted-syntax': [
190 'error',
191 {
192 selector:
193 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchQuery"], [callee.computed=true][callee.property.value="fetchQuery"])',
194 message: 'Use queryClient.query(options) instead.',
195 },
196 {
197 selector:
198 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchQuery"], [callee.computed=true][callee.property.value="prefetchQuery"])',
199 message:
200 'Use queryClient.query(options).catch(noop) instead if errors should be swallowed.',
201 },
202 {
203 selector:
204 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureQueryData"], [callee.computed=true][callee.property.value="ensureQueryData"])',
205 message:
206 "Use queryClient.query({ ...options, staleTime: 'static' }) instead.",
207 },
208 {
209 selector:
210 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchInfiniteQuery"], [callee.computed=true][callee.property.value="fetchInfiniteQuery"])',
211 message: 'Use queryClient.infiniteQuery(options) instead.',
212 },
213 {
214 selector:
215 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchInfiniteQuery"], [callee.computed=true][callee.property.value="prefetchInfiniteQuery"])',
216 message:
217 'Use queryClient.infiniteQuery(options).catch(noop) instead if errors should be swallowed.',
218 },
219 {
220 selector:
221 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureInfiniteQueryData"], [callee.computed=true][callee.property.value="ensureInfiniteQueryData"])',
222 message:
223 "Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead.",
224 },
225 ],
226 },
227 overrides: [
228 {
229 files: ['**/src/**/*.{ts,tsx}'],
230 excludeFiles: [
231 '**/__tests__/**',
232 '**/__testfixtures__/**',
233 '**/*.test.{ts,tsx}',
234 '**/*.test-d.{ts,tsx}',
235 ],
236 jsPlugins: [{ name: 'jsdoc-js', specifier: 'eslint-plugin-jsdoc' }],
237 rules: {
238 ...jsdocRecommendedRules,
239 'jsdoc-js/check-tag-names': [
240 'error',
241 { definedTags: ['defaultValue'] },
242 ],
243 'jsdoc-js/check-param-names': ['error', { checkDestructured: false }],
244 'jsdoc-js/require-jsdoc': [
245 'error',
246 {
247 contexts: [
248 'ExportDefaultDeclaration > ArrowFunctionExpression',
249 'ExportDefaultDeclaration > ClassDeclaration',
250 'ExportDefaultDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
251 'ExportNamedDeclaration > ClassDeclaration',
252 'ExportNamedDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
253 'ExportNamedDeclaration > TSInterfaceDeclaration',
254 'ExportNamedDeclaration > TSInterfaceDeclaration > TSInterfaceBody > TSPropertySignature',
255 'ExportNamedDeclaration > TSTypeAliasDeclaration',
256 'ExportNamedDeclaration > TSTypeAliasDeclaration > TSTypeLiteral > TSPropertySignature',
257 'ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression',
258 ],
259 },
260 ],
261 'jsdoc-js/require-param': ['error', { checkDestructured: false }],
262 'jsdoc-js/check-template-names': 'error',
263 'jsdoc-js/informative-docs': 'error',
264 'jsdoc-js/match-description': 'error',
265 'jsdoc-js/no-bad-blocks': 'error',
266 'jsdoc-js/no-blank-block-descriptions': 'error',
267 'jsdoc-js/no-blank-blocks': 'error',
268 'jsdoc-js/require-asterisk-prefix': 'error',
269 'jsdoc-js/require-description': 'error',
270 'jsdoc-js/require-hyphen-before-param-description': 'error',
271 'jsdoc-js/require-next-description': 'error',
272 'jsdoc-js/require-template-description': 'error',
273 'jsdoc-js/require-throws': 'error',
274 'jsdoc-js/require-throws-description': 'error',
275 'jsdoc-js/require-yields-description': 'error',
276 'jsdoc-js/sort-tags': 'error',
277 },
278 },
279 {
280 files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
281 jsPlugins: [
282 // Unlike the native rule, also checks `expectTypeOf` calls
283 { name: 'vitest-js', specifier: '@vitest/eslint-plugin' },
284 ],
285 rules: {
286 ...pluginVitest.configs.recommended.rules,
287 'vitest/consistent-test-it': [
288 'error',
289 { fn: 'it', withinDescribe: 'it' },
290 ],
291 'vitest/no-standalone-expect': [
292 'error',
293 { additionalTestBlockFunctions: ['itIf'] },
294 ],
295 'vitest/valid-expect': 'off',
296 'vitest-js/valid-expect': 'error',
297 },
298 },
299 ],
300})
301​
302/**
303 * Native Oxlint equivalent of 'eslint-config-preact', applied on top of the root config.
304 *
305 * Not ported because Oxlint does not implement them: `no-dupe-args`, `no-undef`,
306 * `no-undef-init`, `strict`, `react/jsx-no-bind`, `react/jsx-uses-react`,
307 * `react/jsx-uses-vars`, `react/no-deprecated`, `react/prefer-stateless-function`
308 * and `react/require-render-return`.
309 */
310export const preactConfig = defineConfig({
311 plugins: ['import', 'typescript', 'unicorn', 'vitest', 'react'],
312 settings: {
313 react: { version: '16.0' },
314 },
315 rules: {
316 // 'eslint:recommended'
317 'constructor-super': 'error',
318 'getter-return': 'error',
319 'no-case-declarations': 'error',
320 'no-const-assign': 'error',
321 'no-dupe-class-members': 'error',
322 'no-dupe-keys': 'error',
323 'no-func-assign': 'error',
324 'no-new-native-nonconstructor': 'error',
325 'no-obj-calls': 'error',
326 'no-prototype-builtins': 'error',
327 'no-setter-return': 'error',
328 'no-this-before-super': 'error',
329 'no-unexpected-multiline': 'error',
330 'no-unreachable': 'error',
331 'no-unsafe-negation': 'error',
332​
333 // Preact / JSX
334 'react/display-name': ['warn', { ignoreTranspilerName: false }],
335 'react/jsx-key': ['error', { checkFragmentShorthand: true }],
336 'react/jsx-no-comment-textnodes': 'error',
337 'react/jsx-no-duplicate-props': 'error',
338 'react/jsx-no-target-blank': 'error',
339 'react/jsx-no-undef': 'error',
340 'react/no-danger': 'warn',
341 'react/no-did-mount-set-state': 'error',
342 'react/no-did-update-set-state': 'error',
343 'react/no-find-dom-node': 'error',
344 'react/no-is-mounted': 'error',
345 'react/no-string-refs': 'error',
346 'react/prefer-es6-class': 'error',
347 'react/self-closing-comp': 'error',
348​
349 // Hooks
350 'react/rules-of-hooks': 'error',
351 'react/exhaustive-deps': 'warn',
352​
353 // General JavaScript error avoidance
354 'no-caller': 'error',
355 'no-else-return': 'warn',
356 'no-empty-pattern': 'off',
357 'no-iterator': 'error',
358 'no-lonely-if': 'error',
359 'no-multi-str': 'warn',
360 'no-new-wrappers': 'error',
361 'no-proto': 'error',
362 'no-shadow': 'off',
363 'no-unneeded-ternary': 'error',
364 'no-useless-call': 'warn',
365 'no-useless-computed-key': 'warn',
366 'no-useless-concat': 'warn',
367 'no-useless-constructor': 'warn',
368 'no-useless-escape': 'warn',
369 'no-useless-rename': 'warn',
370 'no-var': 'warn',
371​
372 // General JavaScript style
373 'object-shorthand': 'warn',
374 'prefer-arrow-callback': 'warn',
375 'prefer-rest-params': 'warn',
376 'prefer-spread': 'warn',
377 'prefer-template': 'warn',
378 radix: 'warn',
379 'unicode-bom': 'error',
380 },
381})