Open History to see the last commit
1// @ts-check
2
3// @ts-ignore Needed due to moduleResolution Node vs Bundler
4import { tanstackConfig } from '@tanstack/eslint-config'
5import pluginCspell from '@cspell/eslint-plugin'
6import vitest from '@vitest/eslint-plugin'
7import pluginJsdoc from 'eslint-plugin-jsdoc'
8import { defineConfig } from 'eslint/config'
9
10export default defineConfig([
11 ...tanstackConfig,
12 {
13 name: 'tanstack/query/jsdoc',
14 files: ['**/src/**/*.{ts,tsx}'],
15 ignores: [
16 '**/__tests__/**',
17 '**/__testfixtures__/**',
18 '**/*.test.{ts,tsx}',
19 '**/*.test-d.{ts,tsx}',
20 ],
21 extends: [pluginJsdoc.configs['flat/recommended-typescript-error']],
22 rules: {
23 'jsdoc/check-tag-names': ['error', { definedTags: ['defaultValue'] }],
24 'jsdoc/check-param-names': ['error', { checkDestructured: false }],
25 'jsdoc/require-jsdoc': [
26 'error',
27 {
28 contexts: [
29 'ExportDefaultDeclaration > ArrowFunctionExpression',
30 'ExportDefaultDeclaration > ClassDeclaration',
31 'ExportDefaultDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
32 'ExportNamedDeclaration > ClassDeclaration',
33 'ExportNamedDeclaration > ClassDeclaration > ClassBody > MethodDefinition:not([accessibility="private"]):not([key.type="PrivateIdentifier"]):not([kind="constructor"]):not([override=true])',
34 'ExportNamedDeclaration > TSInterfaceDeclaration',
35 'ExportNamedDeclaration > TSInterfaceDeclaration > TSInterfaceBody > TSPropertySignature',
36 'ExportNamedDeclaration > TSTypeAliasDeclaration',
37 'ExportNamedDeclaration > TSTypeAliasDeclaration > TSTypeLiteral > TSPropertySignature',
38 'ExportNamedDeclaration > VariableDeclaration > VariableDeclarator > ArrowFunctionExpression',
39 ],
40 },
41 ],
42 'jsdoc/require-param': ['error', { checkDestructured: false }],
43 'jsdoc/check-template-names': 'error',
44 'jsdoc/informative-docs': 'error',
45 'jsdoc/match-description': 'error',
46 'jsdoc/no-bad-blocks': 'error',
47 'jsdoc/no-blank-block-descriptions': 'error',
48 'jsdoc/no-blank-blocks': 'error',
49 'jsdoc/require-asterisk-prefix': 'error',
50 'jsdoc/require-description': 'error',
51 'jsdoc/require-hyphen-before-param-description': 'error',
52 'jsdoc/require-next-description': 'error',
53 'jsdoc/require-template-description': 'error',
54 'jsdoc/require-throws': 'error',
55 'jsdoc/require-throws-description': 'error',
56 'jsdoc/require-yields-description': 'error',
57 'jsdoc/sort-tags': 'error',
58 },
59 },
60 {
61 name: 'tanstack/query',
62 plugins: {
63 cspell: pluginCspell,
64 },
65 rules: {
66 'cspell/spellchecker': [
67 'warn',
68 {
69 cspell: {
70 words: [
71 'Promisable', // Our public interface
72 'TSES', // @typescript-eslint package's interface
73 'codemod', // We support our codemod
74 'combinate', // Library name
75 'datatag', // Query options tagging
76 'extralight', // Our public interface
77 'jscodeshift',
78 'refetched', // Query refetch operations
79 'refetches', // Query refetch operations
80 'retryer', // Our public interface
81 'solidjs', // Our target framework
82 'tabular-nums', // https://developer.mozilla.org/en-US/docs/Web/CSS/font-variant-numeric
83 'tanstack', // Our package scope
84 'todos', // Too general word to be caught as error
85 'tsqd', // Our public interface (TanStack Query Devtools shorthand)
86 'tsdown', // We use tsdown as builder
87 'typecheck', // Field of vite.config.ts
88 'vue-demi', // dependency of @tanstack/vue-query
89 'ɵkind', // Angular specific
90 'ɵproviders', // Angular specific
91 ],
92 },
93 },
94 ],
95 '@typescript-eslint/no-empty-function': 'off',
96 '@typescript-eslint/no-unsafe-function-type': 'off',
97 'no-case-declarations': 'off',
98 /**
99 * Disallows direct calls to deprecated imperative query methods of `QueryClient`
100 * for new tests and code
101 *
102 * Existing tests that directly test the methods from before the refactoring
103 * will be grandfathered in and allowed to continue using the deprecated methods.
104 * They should not be removed, but new tests should use the new methods instead.
105 */
106 'no-restricted-syntax': [
107 'error',
108 {
109 selector:
110 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchQuery"], [callee.computed=true][callee.property.value="fetchQuery"])',
111 message: 'Use queryClient.query(options) instead.',
112 },
113 {
114 selector:
115 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchQuery"], [callee.computed=true][callee.property.value="prefetchQuery"])',
116 message:
117 'Use queryClient.query(options).catch(noop) instead if errors should be swallowed.',
118 },
119 {
120 selector:
121 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureQueryData"], [callee.computed=true][callee.property.value="ensureQueryData"])',
122 message:
123 "Use queryClient.query({ ...options, staleTime: 'static' }) instead.",
124 },
125 {
126 selector:
127 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="fetchInfiniteQuery"], [callee.computed=true][callee.property.value="fetchInfiniteQuery"])',
128 message: 'Use queryClient.infiniteQuery(options) instead.',
129 },
130 {
131 selector:
132 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="prefetchInfiniteQuery"], [callee.computed=true][callee.property.value="prefetchInfiniteQuery"])',
133 message:
134 'Use queryClient.infiniteQuery(options).catch(noop) instead if errors should be swallowed.',
135 },
136 {
137 selector:
138 'CallExpression[callee.type="MemberExpression"]:matches([callee.property.name="ensureInfiniteQueryData"], [callee.computed=true][callee.property.value="ensureInfiniteQueryData"])',
139 message:
140 "Use queryClient.infiniteQuery({ ...options, staleTime: 'static' }) instead.",
141 },
142 ],
143 'prefer-const': 'off',
144 },
145 },
146 {
147 name: 'tanstack/query/vitest',
148 files: ['**/*.spec.ts*', '**/*.test.ts*', '**/*.test-d.ts*'],
149 plugins: { vitest },
150 rules: {
151 ...vitest.configs.recommended.rules,
152 'vitest/consistent-test-it': [
153 'error',
154 { fn: 'it', withinDescribe: 'it' },
155 ],
156 'vitest/no-standalone-expect': [
157 'error',
158 {
159 additionalTestBlockFunctions: ['itIf'],
160 },
161 ],
162 },
163 settings: { vitest: { typecheck: true } },
164 },
165 {
166 files: ['**/*.test-d.ts', '**/*.test-d.tsx'],
167 rules: {
168 'vitest/expect-expect': 'off',
169 },
170 },
171])