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

index.ts

82 lines2.4 KB

1import { rules } from './rules'
2import type { ESLint, Linter } from 'eslint'
3import type { RuleModule } from '@typescript-eslint/utils/ts-eslint'
4​
5type RuleKey = keyof typeof rules
6​
7/**
8 * The ESLint plugin object: its `rules`, and its configs β€” the legacy `recommended` and
9 * `recommendedStrict`, and the flat `flat/recommended` and `flat/recommended-strict`.
10 */
11export interface Plugin extends Omit<ESLint.Plugin, 'rules'> {
12 /**
13 * The rules of the plugin, keyed by rule name.
14 */
15 rules: Record<RuleKey, RuleModule<any, any, any>>
16 /**
17 * The shareable configs: the legacy `recommended` and `recommendedStrict`, and the flat
18 * `flat/recommended` and `flat/recommended-strict`.
19 */
20 configs: {
21 recommended: ESLint.ConfigData
22 recommendedStrict: ESLint.ConfigData
23 'flat/recommended': Array<Linter.Config>
24 'flat/recommended-strict': Array<Linter.Config>
25 }
27​
28const recommendedRules = {
29 '@tanstack/query/exhaustive-deps': 'error',
30 '@tanstack/query/no-rest-destructuring': 'warn',
31 '@tanstack/query/stable-query-client': 'error',
32 '@tanstack/query/no-unstable-deps': 'error',
33 '@tanstack/query/infinite-query-property-order': 'error',
34 '@tanstack/query/no-void-query-fn': 'error',
35 '@tanstack/query/mutation-property-order': 'error',
36} as const
37​
38const recommendedStrictRules = {
39 ...recommendedRules,
40 '@tanstack/query/prefer-query-options': 'error',
41} as const
42​
43export const plugin = {
44 meta: {
45 name: '@tanstack/eslint-plugin-query',
46 },
47 configs: {
48 recommended: {
49 plugins: ['@tanstack/query'],
50 rules: recommendedRules,
51 },
52 recommendedStrict: {
53 plugins: ['@tanstack/query'],
54 rules: recommendedStrictRules,
55 },
56 'flat/recommended': [
57 {
58 name: 'tanstack/query/flat/recommended',
59 plugins: {
60 '@tanstack/query': {}, // Assigned after plugin object created
61 },
62 rules: recommendedRules,
63 },
64 ],
65 'flat/recommended-strict': [
66 {
67 name: 'tanstack/query/flat/recommended-strict',
68 plugins: {
69 '@tanstack/query': {}, // Assigned after plugin object created
70 },
71 rules: recommendedStrictRules,
72 },
73 ],
74 },
75 rules,
76} satisfies Plugin
77​
78plugin.configs['flat/recommended'][0]!.plugins['@tanstack/query'] = plugin
79plugin.configs['flat/recommended-strict'][0]!.plugins['@tanstack/query'] =
80 plugin
81​
82export default plugin