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

index.ts

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