Skip to content

Commit 9a2a29a

Browse files
committed
refactor: rename 'strictImportCheck' to 'skipImportCheck' and update related documentation
1 parent fcc217d commit 9a2a29a

File tree

15 files changed

+45
-69
lines changed

15 files changed

+45
-69
lines changed

apps/website/content/docs/configurations.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,16 @@ For example, if you are using `@pika/react` instead of `react`, you can set the
4545
import React from "@pika/react";
4646
```
4747

48-
### `strictImportCheck`
48+
### `skipImportCheck`
4949

50-
Check both the shape and the import to determine if an API is from React before applying the rules.
50+
When determining whether an API originates from React, bypass the import source check.
5151

52-
This can prevent false positives when using a irrelevant third-party library that has similar APIs to React.
52+
By default, the rule checks only the shape of the API to determine if it is a React API. If `skipImportCheck` is set to `false`, the rule will check both the shape and the import source.
5353

54-
For example, if you set the `strictImportCheck` to `true`, then the `memo` function from `irrelevant-library` will not be recognized as React's `memo`:
54+
For example, when `skipImportCheck` is set to false, the `memo` function from `unrelated-library` will not be recognized as React's `memo`.
5555

5656
```ts
57-
import { memo } from "irrelevant-library";
57+
import { memo } from "unrelated-library";
5858

5959
const NonComponentFunction = memo(() => {
6060
// ^^^^

apps/website/content/docs/configurations.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ export function SettingsTypeTable() {
1818
description: <Link href="#importsource">The source where React is imported from ⤵</Link>,
1919
default: "react",
2020
},
21-
strictImportCheck: {
21+
skipImportCheck: {
2222
type: "boolean",
2323
description: (
24-
<Link href="#strictimportcheck">
24+
<Link href="#skipImportCheck">
2525
Check both the shape and the import to determine if an API is from React before applying the rules. ⤵
2626
</Link>
2727
),
28-
default: "false",
28+
default: "true",
2929
},
3030
polymorphicPropName: {
3131
type: "string",

packages/core/src/hook/is.ts

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { unsafeDecodeSettings } from "@eslint-react/shared";
55
import type { TSESTree } from "@typescript-eslint/types";
66
import { AST_NODE_TYPES as T } from "@typescript-eslint/types";
77

8+
import { DEFAULT_ESLINT_REACT_SETTINGS } from "../../../shared/src/schemas";
89
import { isInitializedFromReact } from "../utils";
910
import { isReactHookName } from "./hook-name";
1011

@@ -35,23 +36,21 @@ export function isReactHookCall(node: TSESTree.Node | _) {
3536

3637
export function isReactHookCallWithName(context: RuleContext, node: TSESTree.CallExpression | _) {
3738
if (node == null) return constFalse;
38-
const settings = unsafeDecodeSettings(context.settings);
39-
const importSource = settings.importSource ?? "react";
39+
const {
40+
importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
41+
skipImportCheck = true,
42+
} = unsafeDecodeSettings(context.settings);
4043
const initialScope = context.sourceCode.getScope(node);
4144
return (name: string) => {
4245
switch (true) {
4346
case node.callee.type === T.Identifier
4447
&& node.callee.name === name:
45-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
46-
return !settings.strictImportCheck
47-
|| isInitializedFromReact(name, importSource, initialScope);
48+
return skipImportCheck || isInitializedFromReact(name, importSource, initialScope);
4849
case node.callee.type === T.MemberExpression
4950
&& node.callee.property.type === T.Identifier
5051
&& node.callee.property.name === name
5152
&& "name" in node.callee.object:
52-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
53-
return !settings.strictImportCheck
54-
|| isInitializedFromReact(node.callee.object.name, importSource, initialScope);
53+
return skipImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
5554
default:
5655
return false;
5756
}
@@ -73,23 +72,21 @@ export function isReactHookCallWithNameLoose(node: TSESTree.CallExpression | _)
7372
}
7473

7574
export function isReactHookCallWithNameAlias(context: RuleContext, name: string, alias: string[]) {
76-
const settings = unsafeDecodeSettings(context);
77-
const importSource = settings.importSource ?? "react";
75+
const {
76+
importSource = DEFAULT_ESLINT_REACT_SETTINGS.importSource,
77+
skipImportCheck = true,
78+
} = unsafeDecodeSettings(context.settings);
7879
return (node: TSESTree.CallExpression) => {
7980
const initialScope = context.sourceCode.getScope(node);
8081
switch (true) {
8182
case node.callee.type === T.Identifier
8283
&& node.callee.name === name:
83-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
84-
return !settings.strictImportCheck
85-
|| isInitializedFromReact(name, importSource, initialScope);
84+
return skipImportCheck || isInitializedFromReact(name, importSource, initialScope);
8685
case node.callee.type === T.MemberExpression
8786
&& node.callee.property.type === T.Identifier
8887
&& node.callee.property.name === name
8988
&& "name" in node.callee.object:
90-
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
91-
return !settings.strictImportCheck
92-
|| isInitializedFromReact(node.callee.object.name, importSource, initialScope);
89+
return skipImportCheck || isInitializedFromReact(node.callee.object.name, importSource, initialScope);
9390
default:
9491
return alias.some(isReactHookCallWithNameLoose(node));
9592
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ export function isFromReactStrict(
3939

4040
export function isFromReact(name: string) {
4141
return (context: RuleContext, node: TSESTree.Identifier | TSESTree.MemberExpression) => {
42-
const { importSource = defaultImportSource, strictImportCheck = false } = unsafeDecodeSettings(context.settings);
43-
if (!strictImportCheck) return isFromReactLoose(node, name);
42+
const { importSource = defaultImportSource, skipImportCheck = true } = unsafeDecodeSettings(context.settings);
43+
if (skipImportCheck) return isFromReactLoose(node, name);
4444
return isFromReactStrict(node, name, importSource, context.sourceCode.getScope(node));
4545
};
4646
}
@@ -88,8 +88,8 @@ export function isFromReactMemberStrict(
8888

8989
export function isFromReactMember(memberName: string, name: string) {
9090
return (context: RuleContext, node: TSESTree.MemberExpression) => {
91-
const { importSource = defaultImportSource, strictImportCheck = false } = unsafeDecodeSettings(context.settings);
92-
if (!strictImportCheck) return isFromReactMemberLoose(node, memberName, name);
91+
const { importSource = defaultImportSource, skipImportCheck = true } = unsafeDecodeSettings(context.settings);
92+
if (skipImportCheck) return isFromReactMemberLoose(node, memberName, name);
9393
return isFromReactMemberStrict(node, memberName, name, importSource, context.sourceCode.getScope(node));
9494
};
9595
}

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

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ ruleTester.run(RULE_NAME, rule, {
2727
settings: {
2828
"react-x": {
2929
importSource: "@pika/react",
30-
strictImportCheck: true,
3130
},
3231
},
3332
},
@@ -45,7 +44,6 @@ ruleTester.run(RULE_NAME, rule, {
4544
settings: {
4645
"react-x": {
4746
importSource: "@pika/react",
48-
strictImportCheck: true,
4947
},
5048
},
5149
},
@@ -66,7 +64,6 @@ ruleTester.run(RULE_NAME, rule, {
6664
settings: {
6765
"react-x": {
6866
importSource: "@pika/react",
69-
strictImportCheck: true,
7067
},
7168
},
7269
},
@@ -85,7 +82,6 @@ ruleTester.run(RULE_NAME, rule, {
8582
settings: {
8683
"react-x": {
8784
importSource: "@pika/react",
88-
strictImportCheck: true,
8985
},
9086
},
9187
},
@@ -107,7 +103,6 @@ ruleTester.run(RULE_NAME, rule, {
107103
settings: {
108104
"react-x": {
109105
importSource: "@pika/react",
110-
strictImportCheck: true,
111106
},
112107
},
113108
},
@@ -132,7 +127,6 @@ ruleTester.run(RULE_NAME, rule, {
132127
settings: {
133128
"react-x": {
134129
importSource: "@pika/react",
135-
strictImportCheck: true,
136130
},
137131
},
138132
},
@@ -154,7 +148,6 @@ ruleTester.run(RULE_NAME, rule, {
154148
settings: {
155149
"react-x": {
156150
importSource: "@pika/react",
157-
strictImportCheck: true,
158151
},
159152
},
160153
},
@@ -171,7 +164,6 @@ ruleTester.run(RULE_NAME, rule, {
171164
settings: {
172165
"react-x": {
173166
importSource: "@pika/react",
174-
strictImportCheck: true,
175167
},
176168
},
177169
},
@@ -189,7 +181,6 @@ ruleTester.run(RULE_NAME, rule, {
189181
settings: {
190182
"react-x": {
191183
importSource: "@pika/react",
192-
strictImportCheck: true,
193184
},
194185
},
195186
},
@@ -210,7 +201,6 @@ ruleTester.run(RULE_NAME, rule, {
210201
settings: {
211202
"react-x": {
212203
importSource: "@pika/react",
213-
strictImportCheck: true,
214204
},
215205
},
216206
},
@@ -229,7 +219,6 @@ ruleTester.run(RULE_NAME, rule, {
229219
settings: {
230220
"react-x": {
231221
importSource: "@pika/react",
232-
strictImportCheck: true,
233222
},
234223
},
235224
},
@@ -251,7 +240,6 @@ ruleTester.run(RULE_NAME, rule, {
251240
settings: {
252241
"react-x": {
253242
importSource: "@pika/react",
254-
strictImportCheck: true,
255243
},
256244
},
257245
},
@@ -282,7 +270,6 @@ ruleTester.run(RULE_NAME, rule, {
282270
settings: {
283271
"react-x": {
284272
importSource: "@pika/react",
285-
strictImportCheck: true,
286273
},
287274
},
288275
},
@@ -302,7 +289,6 @@ ruleTester.run(RULE_NAME, rule, {
302289
settings: {
303290
"react-x": {
304291
importSource: "react",
305-
strictImportCheck: true,
306292
},
307293
},
308294
},
@@ -322,7 +308,6 @@ ruleTester.run(RULE_NAME, rule, {
322308
settings: {
323309
"react-x": {
324310
importSource: "react",
325-
strictImportCheck: true,
326311
},
327312
},
328313
},
@@ -336,7 +321,6 @@ ruleTester.run(RULE_NAME, rule, {
336321
settings: {
337322
"react-x": {
338323
importSource: "react",
339-
strictImportCheck: true,
340324
},
341325
},
342326
},
@@ -348,7 +332,6 @@ ruleTester.run(RULE_NAME, rule, {
348332
settings: {
349333
"react-x": {
350334
importSource: "react",
351-
strictImportCheck: true,
352335
},
353336
},
354337
},
@@ -360,7 +343,6 @@ ruleTester.run(RULE_NAME, rule, {
360343
settings: {
361344
"react-x": {
362345
importSource: "react",
363-
strictImportCheck: true,
364346
},
365347
},
366348
},
@@ -372,7 +354,6 @@ ruleTester.run(RULE_NAME, rule, {
372354
settings: {
373355
"react-x": {
374356
importSource: "react",
375-
strictImportCheck: true,
376357
},
377358
},
378359
},
@@ -386,7 +367,6 @@ ruleTester.run(RULE_NAME, rule, {
386367
settings: {
387368
"react-x": {
388369
importSource: "react",
389-
strictImportCheck: true,
390370
},
391371
},
392372
},
@@ -402,7 +382,6 @@ ruleTester.run(RULE_NAME, rule, {
402382
settings: {
403383
"react-x": {
404384
importSource: "react",
405-
strictImportCheck: true,
406385
},
407386
},
408387
},

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ ruleTester.run(RULE_NAME, rule, {
3636
}],
3737
settings: {
3838
"react-x": {
39-
strictImportCheck: false,
39+
skipImportCheck: true,
4040
},
4141
},
4242
},
@@ -159,7 +159,7 @@ ruleTester.run(RULE_NAME, rule, {
159159
`,
160160
settings: {
161161
"react-x": {
162-
strictImportCheck: true,
162+
skipImportCheck: false,
163163
},
164164
},
165165
},

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

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

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

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

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

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

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

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

0 commit comments

Comments
 (0)