-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy patheslint.config.mjs
More file actions
212 lines (210 loc) Β· 7.46 KB
/
Copy patheslint.config.mjs
File metadata and controls
212 lines (210 loc) Β· 7.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
import js from '@eslint/js';
import globals from 'globals';
import tseslint from 'typescript-eslint';
import reactHooksPlugin from 'eslint-plugin-react-hooks';
import importPlugin from 'eslint-plugin-import';
import sortDestructureKeysPlugin from 'eslint-plugin-sort-destructure-keys';
import reactPlugin from 'eslint-plugin-react';
import vitestPlugin from '@vitest/eslint-plugin';
export default tseslint.config(
{
ignores: [
'dist',
'src/@types',
'*.{js,ts}',
'.yarn',
'examples/*/dist',
'examples/*/node_modules',
'examples/*/docs-playwright',
],
},
{
name: 'default',
extends: [
js.configs.recommended,
...tseslint.configs.recommended,
reactPlugin.configs.flat.recommended,
],
files: ['src/**/*.{js,ts,jsx,tsx}', 'examples/*/src/**/*.{js,ts,jsx,tsx}'],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
plugins: {
'react-hooks': reactHooksPlugin,
import: importPlugin,
'sort-destructure-keys': sortDestructureKeysPlugin,
},
settings: {
react: {
version: 'detect',
},
},
rules: {
camelcase: 'off',
semi: ['warn', 'always'],
eqeqeq: ['error', 'smart'],
'array-callback-return': 'error',
'arrow-body-style': 'error',
'comma-dangle': 'off',
'default-case': 'error',
'jsx-quotes': ['error', 'prefer-single'],
'linebreak-style': ['error', 'unix'],
'no-console': 'off',
'no-mixed-spaces-and-tabs': 'warn',
'no-self-compare': 'error',
'no-underscore-dangle': [
'error',
{ allow: ['_internalState'], allowAfterThis: true },
],
'no-use-before-define': 'off',
'no-useless-concat': 'error',
'no-var': 'error',
'no-script-url': 'error',
'no-continue': 'off',
'object-shorthand': 'warn',
'prefer-const': 'warn',
'require-await': 'error',
'sort-destructure-keys/sort-destructure-keys': ['error', { caseSensitive: false }],
'sort-imports': [
'error',
{
allowSeparatedGroups: true,
ignoreCase: true,
ignoreDeclarationSort: true,
ignoreMemberSort: false,
memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
},
],
'sort-keys': ['error', 'asc', { caseSensitive: false, minKeys: 2, natural: false }],
'valid-typeof': 'error',
'max-classes-per-file': 'off',
'no-unused-expressions': 'off',
'import/prefer-default-export': 'off',
'import/extensions': 'off',
'import/no-extraneous-dependencies': [
'error',
{
devDependencies: true, // TODO: set to false once React is in the dependencies (not devDependencies)
optionalDependencies: false,
peerDependencies: false,
},
],
'no-unused-vars': 'off',
'@typescript-eslint/no-unused-vars': [
'warn',
{ ignoreRestSiblings: false, caughtErrors: 'none' },
],
'@typescript-eslint/no-unsafe-function-type': 'error',
'@typescript-eslint/consistent-type-imports': 'error',
'@typescript-eslint/no-wrapper-object-types': 'error',
'@typescript-eslint/no-non-null-assertion': 'error',
'no-empty-function': 'off',
'@typescript-eslint/no-empty-function': 'warn',
'@typescript-eslint/no-require-imports': 'off', // TODO: remove this rule once all files are .mjs (and require is not used)
'react/prop-types': 'off',
'react/react-in-jsx-scope': 'off',
'react/display-name': 'warn',
'react/jsx-sort-props': [
'error',
{
callbacksLast: false,
ignoreCase: true,
noSortAlphabetically: false,
reservedFirst: false,
shorthandFirst: false,
shorthandLast: false,
},
],
'react-hooks/rules-of-hooks': 'warn',
'react-hooks/exhaustive-deps': 'error',
},
},
{
// Forbid patterns that silently break on React 17 or 18. Approved alternatives:
// - useId β src/utils/useStableId.ts
// - useSyncExternalStore β use-sync-external-store/shim
// - useEffectEvent, use() β not allowed; SDK supports React 17+.
// - ref as a regular prop β wrap the component with React.forwardRef
name: 'react-compat',
files: ['src/**/*.{ts,tsx}'],
ignores: [
'src/components/UtilityComponents/useStableId.ts',
'src/**/__tests__/**',
'src/mock-builders/**',
],
rules: {
'no-restricted-imports': [
'error',
{
paths: [
{
name: 'react',
importNames: ['useId', 'useSyncExternalStore', 'useEffectEvent', 'use'],
message:
'React 18+/19-only API. Use useStableId from src/utils/useStableId, useSyncExternalStore from use-sync-external-store/shim. useEffectEvent and use() are not allowed: SDK supports React 17+.',
},
],
},
],
'no-restricted-syntax': [
'error',
{
selector:
"MemberExpression[object.name='React'][property.name=/^(useId|useSyncExternalStore|useEffectEvent|use)$/]",
message:
'React 18+/19-only API. Use useStableId / use-sync-external-store/shim instead of React.<api>.',
},
{
selector: "TSPropertySignature[key.name='ref']",
message:
'`ref` declared as a regular prop. React 17 and 18 only deliver `ref` to components wrapped in `React.forwardRef` β declare the component with `forwardRef` instead of putting `ref` in the prop type.',
},
{
selector:
":matches(FunctionDeclaration, FunctionExpression, ArrowFunctionExpression) > ObjectPattern > Property[key.name='ref']",
message:
'`ref` destructured from props. React 17 and 18 only deliver `ref` to components wrapped in `React.forwardRef` β use `React.forwardRef((props, ref) => β¦)` and take `ref` as the second parameter instead.',
},
],
},
},
{
name: 'vitest',
files: ['src/**/__tests__/**', 'src/mock-builders/**'],
plugins: { vitest: vitestPlugin },
languageOptions: {
globals: vitestPlugin.environments.env.globals,
},
rules: {
'vitest/expect-expect': 'off',
'vitest/no-conditional-expect': 'off',
'vitest/prefer-inline-snapshots': 'off',
'vitest/prefer-lowercase-title': 'off',
'vitest/prefer-expect-assertions': 'off',
'vitest/no-hooks': 'off',
'vitest/prefer-spy-on': 'warn',
'@typescript-eslint/no-empty-function': 'off', // explicitly disable for tests
'@typescript-eslint/no-explicit-any': 'off', // test mocks frequently need any
'@typescript-eslint/no-non-null-assertion': 'off', // DOM queries in tests commonly use !
'@typescript-eslint/consistent-type-imports': [
'error',
{ disallowTypeAnnotations: false },
], // allow typeof import() in vi.mock importOriginal
},
},
{
// Example apps inherit the SDK's plugins + recommended rules but relax
// the cosmetic style rules that don't add value in demo code. Real bug
// patterns (react-hooks deps, no-unknown-property for SVG, undeclared
// imports, etc.) stay on.
name: 'examples',
files: ['examples/*/src/**/*.{js,ts,jsx,tsx}'],
rules: {
'sort-keys': 'off',
'sort-destructure-keys/sort-destructure-keys': 'off',
'react/jsx-sort-props': 'off',
'@typescript-eslint/no-non-null-assertion': 'off',
},
},
);