Skip to content

Commit 7cfbadc

Browse files
authored
refactor: update the default behavior of import check, closes #858 (#860)
1 parent 1a597ba commit 7cfbadc

File tree

17 files changed

+86
-46
lines changed

17 files changed

+86
-46
lines changed

packages/core/docs/functions/isInitializedFromReact.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ The top-level identifier's name
2020

2121
Initial scope to search for the identifier
2222

23-
**settings**: `Partial`\<`Pick`\<`object`, `"importSource"` \| `"skipImportCheck"`\>\>
23+
**settings**: `Partial`\<`Pick`\<`object`, `"importSource"` \| `"strictImportCheck"`\>\>
2424

2525
ESLint React settings
2626

packages/core/src/is-initialized-from-react.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,9 @@ import { isMatching, match } from "ts-pattern";
1515
export function isInitializedFromReact(
1616
name: string,
1717
initialScope: Scope,
18-
settings: Partial<Pick<ESLintReactSettings, "importSource" | "skipImportCheck">>,
18+
settings: Partial<Pick<ESLintReactSettings, "importSource" | "strictImportCheck">>,
1919
): boolean {
20-
if (settings.skipImportCheck) return true;
20+
if (!settings.strictImportCheck) return true;
2121
// Optimistic assertion when identifier is named react
2222
if (name.toLowerCase() === "react") return true;
2323
const { importSource = "react" } = settings;

packages/plugins/eslint-plugin-react-debug/src/rules/is-from-react.spec.ts

+21-21
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ ruleTester.run(RULE_NAME, rule, {
2727
settings: {
2828
"react-x": {
2929
importSource: "@pika/react",
30-
skipImportCheck: false,
30+
strictImportCheck: true,
3131
},
3232
},
3333
},
@@ -45,7 +45,7 @@ ruleTester.run(RULE_NAME, rule, {
4545
settings: {
4646
"react-x": {
4747
importSource: "@pika/react",
48-
skipImportCheck: false,
48+
strictImportCheck: true,
4949
},
5050
},
5151
},
@@ -66,7 +66,7 @@ ruleTester.run(RULE_NAME, rule, {
6666
settings: {
6767
"react-x": {
6868
importSource: "@pika/react",
69-
skipImportCheck: false,
69+
strictImportCheck: true,
7070
},
7171
},
7272
},
@@ -85,7 +85,7 @@ ruleTester.run(RULE_NAME, rule, {
8585
settings: {
8686
"react-x": {
8787
importSource: "@pika/react",
88-
skipImportCheck: false,
88+
strictImportCheck: true,
8989
},
9090
},
9191
},
@@ -107,7 +107,7 @@ ruleTester.run(RULE_NAME, rule, {
107107
settings: {
108108
"react-x": {
109109
importSource: "@pika/react",
110-
skipImportCheck: false,
110+
strictImportCheck: true,
111111
},
112112
},
113113
},
@@ -132,7 +132,7 @@ ruleTester.run(RULE_NAME, rule, {
132132
settings: {
133133
"react-x": {
134134
importSource: "@pika/react",
135-
skipImportCheck: false,
135+
strictImportCheck: true,
136136
},
137137
},
138138
},
@@ -154,7 +154,7 @@ ruleTester.run(RULE_NAME, rule, {
154154
settings: {
155155
"react-x": {
156156
importSource: "@pika/react",
157-
skipImportCheck: false,
157+
strictImportCheck: true,
158158
},
159159
},
160160
},
@@ -171,7 +171,7 @@ ruleTester.run(RULE_NAME, rule, {
171171
settings: {
172172
"react-x": {
173173
importSource: "@pika/react",
174-
skipImportCheck: false,
174+
strictImportCheck: true,
175175
},
176176
},
177177
},
@@ -189,7 +189,7 @@ ruleTester.run(RULE_NAME, rule, {
189189
settings: {
190190
"react-x": {
191191
importSource: "@pika/react",
192-
skipImportCheck: false,
192+
strictImportCheck: true,
193193
},
194194
},
195195
},
@@ -210,7 +210,7 @@ ruleTester.run(RULE_NAME, rule, {
210210
settings: {
211211
"react-x": {
212212
importSource: "@pika/react",
213-
skipImportCheck: false,
213+
strictImportCheck: true,
214214
},
215215
},
216216
},
@@ -229,7 +229,7 @@ ruleTester.run(RULE_NAME, rule, {
229229
settings: {
230230
"react-x": {
231231
importSource: "@pika/react",
232-
skipImportCheck: false,
232+
strictImportCheck: true,
233233
},
234234
},
235235
},
@@ -251,7 +251,7 @@ ruleTester.run(RULE_NAME, rule, {
251251
settings: {
252252
"react-x": {
253253
importSource: "@pika/react",
254-
skipImportCheck: false,
254+
strictImportCheck: true,
255255
},
256256
},
257257
},
@@ -276,7 +276,7 @@ ruleTester.run(RULE_NAME, rule, {
276276
settings: {
277277
"react-x": {
278278
importSource: "@pika/react",
279-
skipImportCheck: false,
279+
strictImportCheck: true,
280280
},
281281
},
282282
},
@@ -296,7 +296,7 @@ ruleTester.run(RULE_NAME, rule, {
296296
settings: {
297297
"react-x": {
298298
importSource: "react",
299-
skipImportCheck: false,
299+
strictImportCheck: true,
300300
},
301301
},
302302
},
@@ -316,7 +316,7 @@ ruleTester.run(RULE_NAME, rule, {
316316
settings: {
317317
"react-x": {
318318
importSource: "react",
319-
skipImportCheck: false,
319+
strictImportCheck: true,
320320
},
321321
},
322322
},
@@ -330,7 +330,7 @@ ruleTester.run(RULE_NAME, rule, {
330330
settings: {
331331
"react-x": {
332332
importSource: "react",
333-
skipImportCheck: false,
333+
strictImportCheck: true,
334334
},
335335
},
336336
},
@@ -342,7 +342,7 @@ ruleTester.run(RULE_NAME, rule, {
342342
settings: {
343343
"react-x": {
344344
importSource: "react",
345-
skipImportCheck: false,
345+
strictImportCheck: true,
346346
},
347347
},
348348
},
@@ -354,7 +354,7 @@ ruleTester.run(RULE_NAME, rule, {
354354
settings: {
355355
"react-x": {
356356
importSource: "react",
357-
skipImportCheck: false,
357+
strictImportCheck: true,
358358
},
359359
},
360360
},
@@ -366,7 +366,7 @@ ruleTester.run(RULE_NAME, rule, {
366366
settings: {
367367
"react-x": {
368368
importSource: "react",
369-
skipImportCheck: false,
369+
strictImportCheck: true,
370370
},
371371
},
372372
},
@@ -380,7 +380,7 @@ ruleTester.run(RULE_NAME, rule, {
380380
settings: {
381381
"react-x": {
382382
importSource: "react",
383-
skipImportCheck: false,
383+
strictImportCheck: true,
384384
},
385385
},
386386
},
@@ -396,7 +396,7 @@ ruleTester.run(RULE_NAME, rule, {
396396
settings: {
397397
"react-x": {
398398
importSource: "react",
399-
skipImportCheck: false,
399+
strictImportCheck: true,
400400
},
401401
},
402402
},

packages/plugins/eslint-plugin-react-dom/src/index.ts

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ const DEFAULT_ESLINT_REACT_SETTINGS = {
2727
],
2828
},
2929
],
30-
skipImportCheck: false,
3130
} as const satisfies ESLintReactSettings;
3231

3332
export default {

packages/plugins/eslint-plugin-react-naming-convention/src/rules/use-state.spec.ts

+51
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,43 @@ import rule, { RULE_NAME } from "./use-state";
33

44
ruleTester.run(RULE_NAME, rule, {
55
invalid: [
6+
{
7+
code: /* tsx */ `
8+
function Component() {
9+
const [state, setValue] = useState(0);
10+
11+
return <div />;
12+
}
13+
`,
14+
errors: [{
15+
messageId: "useState",
16+
data: {
17+
setterName: "setState",
18+
stateName: "state",
19+
},
20+
}],
21+
},
22+
{
23+
code: /* tsx */ `
24+
function Component() {
25+
const [state, setValue] = useState(0);
26+
27+
return <div />;
28+
}
29+
`,
30+
errors: [{
31+
messageId: "useState",
32+
data: {
33+
setterName: "setState",
34+
stateName: "state",
35+
},
36+
}],
37+
settings: {
38+
"react-x": {
39+
strictImportCheck: false,
40+
},
41+
},
42+
},
643
{
744
code: /* tsx */ `
845
import { useState } from "react";
@@ -112,5 +149,19 @@ ruleTester.run(RULE_NAME, rule, {
112149
return <div />;
113150
}
114151
`,
152+
{
153+
code: /* tsx */ `
154+
function Component() {
155+
const [state, setValue] = useState(0);
156+
157+
return <div />;
158+
}
159+
`,
160+
settings: {
161+
"react-x": {
162+
strictImportCheck: true,
163+
},
164+
},
165+
},
115166
],
116167
});

packages/plugins/eslint-plugin-react-web-api/src/index.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@ import noLeakedInterval from "./rules/no-leaked-interval";
66
import noLeakedResizeObserver from "./rules/no-leaked-resize-observer";
77
import noLeakedTimeout from "./rules/no-leaked-timeout";
88

9-
const DEFAULT_ESLINT_REACT_SETTINGS = {
10-
skipImportCheck: true,
11-
} as const satisfies ESLintReactSettings;
9+
const DEFAULT_ESLINT_REACT_SETTINGS = {} as const satisfies ESLintReactSettings;
1210

1311
export default {
1412
meta: {

packages/plugins/eslint-plugin-react-x/src/index.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ const DEFAULT_ESLINT_REACT_SETTINGS = {
5959
useLayoutEffect: ["useIsomorphicLayoutEffect"],
6060
},
6161
polymorphicPropName: "as",
62-
skipImportCheck: false,
62+
strictImportCheck: true,
6363
version: "detect",
6464
} as const satisfies ESLintReactSettings;
6565

packages/plugins/eslint-plugin-react-x/src/rules/no-children-count.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ ruleTester.run(RULE_NAME, rule, {
9696
`,
9797
settings: {
9898
"react-x": {
99-
skipImportCheck: false,
99+
strictImportCheck: true,
100100
},
101101
},
102102
},

packages/plugins/eslint-plugin-react-x/src/rules/no-children-for-each.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ ruleTester.run(RULE_NAME, rule, {
9292
`,
9393
settings: {
9494
"react-x": {
95-
skipImportCheck: false,
95+
strictImportCheck: true,
9696
},
9797
},
9898
},

packages/plugins/eslint-plugin-react-x/src/rules/no-children-map.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ ruleTester.run(RULE_NAME, rule, {
106106
`,
107107
settings: {
108108
"react-x": {
109-
skipImportCheck: false,
109+
strictImportCheck: true,
110110
},
111111
},
112112
},

packages/plugins/eslint-plugin-react-x/src/rules/no-children-only.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ ruleTester.run(RULE_NAME, rule, {
7171
`,
7272
settings: {
7373
"react-x": {
74-
skipImportCheck: false,
74+
strictImportCheck: true,
7575
},
7676
},
7777
},

packages/plugins/eslint-plugin-react-x/src/rules/no-children-to-array.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ ruleTester.run(RULE_NAME, rule, {
103103
`,
104104
settings: {
105105
"react-x": {
106-
skipImportCheck: false,
106+
strictImportCheck: true,
107107
},
108108
},
109109
},

packages/plugins/eslint-plugin-react-x/src/rules/no-useless-fragment.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ ruleTester.run(RULE_NAME, rule, {
202202
code: /* tsx */ `<NotReact.Fragment />`,
203203
settings: {
204204
"react-x": {
205-
skipImportCheck: false,
205+
strictImportCheck: true,
206206
},
207207
},
208208
},

packages/plugins/eslint-plugin-react-x/src/rules/prefer-shorthand-fragment.spec.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ ruleTester.run(RULE_NAME, rule, {
3737
code: /* tsx */ `<NotReact.Fragment />`,
3838
settings: {
3939
"react-x": {
40-
skipImportCheck: false,
40+
strictImportCheck: true,
4141
},
4242
},
4343
},

packages/shared/docs/variables/INITIAL_ESLINT_REACT_SETTINGS.md

-6
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,3 @@
99
> `const` **INITIAL\_ESLINT\_REACT\_SETTINGS**: `object`
1010
1111
The initial settings for "react-x".
12-
13-
## Type declaration
14-
15-
### skipImportCheck
16-
17-
> `readonly` **skipImportCheck**: `false` = `false`

packages/shared/src/schemas.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ export const ESLintReactSettingsSchema = object({
122122
/**
123123
* @internal
124124
*/
125-
skipImportCheck: optional(boolean(), true),
125+
strictImportCheck: optional(boolean()),
126126
/**
127127
* React version to use, "detect" means auto detect React version from the project’s dependencies.
128128
* If `importSource` is specified, an equivalent version of React should be provided here.

packages/shared/src/settings.ts

+1-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,7 @@ import { ESLintSettingsSchema } from "./schemas";
1313
/**
1414
* The initial settings for "react-x".
1515
*/
16-
export const INITIAL_ESLINT_REACT_SETTINGS = {
17-
skipImportCheck: false,
18-
} as const satisfies ESLintReactSettings;
16+
export const INITIAL_ESLINT_REACT_SETTINGS = {} as const satisfies ESLintReactSettings;
1917

2018
// #endregion
2119

0 commit comments

Comments
 (0)