eslint-plugin-react-hooks-extra 1.10.1 → 1.10.2-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -8
- package/dist/index.js +13 -1
- package/dist/index.mjs +13 -1
- package/package.json +8 -8
package/README.md
CHANGED
|
@@ -26,15 +26,15 @@ export default [
|
|
|
26
26
|
js.configs.recommended,
|
|
27
27
|
{
|
|
28
28
|
files: ["**/*.{ts,tsx}"],
|
|
29
|
-
plugins:
|
|
29
|
+
plugins: {
|
|
30
30
|
"react-hooks-extra": reactHooksExtra,
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
31
|
+
},
|
|
32
|
+
rules: {
|
|
33
|
+
// react-hooks-extra recommended rules
|
|
34
|
+
"react-hooks-extra/no-direct-set-state-in-use-effect": "warn",
|
|
35
|
+
"react-hooks-extra/no-direct-set-state-in-use-layout-effect": "warn",
|
|
36
|
+
"react-hooks-extra/prefer-use-state-lazy-initialization": "warn",
|
|
37
|
+
},
|
|
38
38
|
},
|
|
39
39
|
];
|
|
40
40
|
```
|
package/dist/index.js
CHANGED
|
@@ -11,7 +11,7 @@ var tsPattern = require('ts-pattern');
|
|
|
11
11
|
|
|
12
12
|
// package.json
|
|
13
13
|
var name = "eslint-plugin-react-hooks-extra";
|
|
14
|
-
var version = "1.10.
|
|
14
|
+
var version = "1.10.2-beta.2";
|
|
15
15
|
var createRule = shared.createRuleForPlugin("hooks-extra");
|
|
16
16
|
function isFromHookCall(name2, context, settings, predicate = tools.F.constTrue) {
|
|
17
17
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
@@ -35,9 +35,13 @@ function isSetFunctionCall(context, settings) {
|
|
|
35
35
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
36
36
|
return (node) => {
|
|
37
37
|
switch (node.callee.type) {
|
|
38
|
+
// const [data, setData] = useState();
|
|
39
|
+
// setData();
|
|
38
40
|
case types.AST_NODE_TYPES.Identifier: {
|
|
39
41
|
return isIdFromUseStateCall(node.callee);
|
|
40
42
|
}
|
|
43
|
+
// const data = useState();
|
|
44
|
+
// data[1]();
|
|
41
45
|
case types.AST_NODE_TYPES.MemberExpression: {
|
|
42
46
|
if (!("name" in node.callee.object)) return false;
|
|
43
47
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -45,6 +49,8 @@ function isSetFunctionCall(context, settings) {
|
|
|
45
49
|
if (property?.value === 1) return isIdFromUseStateCall(node.callee.object);
|
|
46
50
|
return false;
|
|
47
51
|
}
|
|
52
|
+
// const data = useState();
|
|
53
|
+
// data.at(1)();
|
|
48
54
|
case types.AST_NODE_TYPES.CallExpression: {
|
|
49
55
|
const callee = node.callee.callee;
|
|
50
56
|
if (callee.type !== types.AST_NODE_TYPES.MemberExpression) return false;
|
|
@@ -101,6 +107,7 @@ var ensure_custom_hooks_using_other_hooks_default = createRule({
|
|
|
101
107
|
},
|
|
102
108
|
name: RULE_NAME,
|
|
103
109
|
create(context) {
|
|
110
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
104
111
|
const { ctx, listeners } = core.useHookCollector();
|
|
105
112
|
return {
|
|
106
113
|
...listeners,
|
|
@@ -135,6 +142,7 @@ var ensure_use_callback_has_non_empty_deps_default = createRule({
|
|
|
135
142
|
},
|
|
136
143
|
name: RULE_NAME2,
|
|
137
144
|
create(context) {
|
|
145
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
138
146
|
const alias = shared.decodeSettings(context.settings).additionalHooks?.useCallback ?? [];
|
|
139
147
|
return {
|
|
140
148
|
CallExpression(node) {
|
|
@@ -213,6 +221,7 @@ var ensure_use_memo_has_non_empty_deps_default = createRule({
|
|
|
213
221
|
},
|
|
214
222
|
name: RULE_NAME3,
|
|
215
223
|
create(context) {
|
|
224
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
216
225
|
const alias = shared.decodeSettings(context.settings).additionalHooks?.useMemo ?? [];
|
|
217
226
|
return {
|
|
218
227
|
CallExpression(node) {
|
|
@@ -291,6 +300,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
291
300
|
},
|
|
292
301
|
name: RULE_NAME4,
|
|
293
302
|
create(context) {
|
|
303
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
294
304
|
const settings = shared.decodeSettings(context.settings);
|
|
295
305
|
const additionalHooks = settings.additionalHooks ?? {};
|
|
296
306
|
const isUseEffectCall = core.isReactHookCallWithNameAlias("useEffect", context, additionalHooks.useEffect ?? []);
|
|
@@ -461,6 +471,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
461
471
|
},
|
|
462
472
|
name: RULE_NAME5,
|
|
463
473
|
create(context) {
|
|
474
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
464
475
|
const settings = shared.decodeSettings(context.settings);
|
|
465
476
|
const additionalHooks = settings.additionalHooks ?? {};
|
|
466
477
|
const isUseEffectCall = core.isReactHookCallWithNameAlias(
|
|
@@ -636,6 +647,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
636
647
|
},
|
|
637
648
|
name: RULE_NAME6,
|
|
638
649
|
create(context) {
|
|
650
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
639
651
|
const alias = shared.decodeSettings(context.settings).additionalHooks?.useState ?? [];
|
|
640
652
|
return {
|
|
641
653
|
CallExpression(node) {
|
package/dist/index.mjs
CHANGED
|
@@ -9,7 +9,7 @@ import { match, isMatching } from 'ts-pattern';
|
|
|
9
9
|
|
|
10
10
|
// package.json
|
|
11
11
|
var name = "eslint-plugin-react-hooks-extra";
|
|
12
|
-
var version = "1.10.
|
|
12
|
+
var version = "1.10.2-beta.2";
|
|
13
13
|
var createRule = createRuleForPlugin("hooks-extra");
|
|
14
14
|
function isFromHookCall(name2, context, settings, predicate = F.constTrue) {
|
|
15
15
|
const hookAlias = settings.additionalHooks?.[name2] ?? [];
|
|
@@ -33,9 +33,13 @@ function isSetFunctionCall(context, settings) {
|
|
|
33
33
|
const isIdFromUseStateCall = isFromUseStateCall(context, settings);
|
|
34
34
|
return (node) => {
|
|
35
35
|
switch (node.callee.type) {
|
|
36
|
+
// const [data, setData] = useState();
|
|
37
|
+
// setData();
|
|
36
38
|
case AST_NODE_TYPES.Identifier: {
|
|
37
39
|
return isIdFromUseStateCall(node.callee);
|
|
38
40
|
}
|
|
41
|
+
// const data = useState();
|
|
42
|
+
// data[1]();
|
|
39
43
|
case AST_NODE_TYPES.MemberExpression: {
|
|
40
44
|
if (!("name" in node.callee.object)) return false;
|
|
41
45
|
const initialScope = context.sourceCode.getScope(node);
|
|
@@ -43,6 +47,8 @@ function isSetFunctionCall(context, settings) {
|
|
|
43
47
|
if (property?.value === 1) return isIdFromUseStateCall(node.callee.object);
|
|
44
48
|
return false;
|
|
45
49
|
}
|
|
50
|
+
// const data = useState();
|
|
51
|
+
// data.at(1)();
|
|
46
52
|
case AST_NODE_TYPES.CallExpression: {
|
|
47
53
|
const callee = node.callee.callee;
|
|
48
54
|
if (callee.type !== AST_NODE_TYPES.MemberExpression) return false;
|
|
@@ -99,6 +105,7 @@ var ensure_custom_hooks_using_other_hooks_default = createRule({
|
|
|
99
105
|
},
|
|
100
106
|
name: RULE_NAME,
|
|
101
107
|
create(context) {
|
|
108
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
102
109
|
const { ctx, listeners } = useHookCollector();
|
|
103
110
|
return {
|
|
104
111
|
...listeners,
|
|
@@ -133,6 +140,7 @@ var ensure_use_callback_has_non_empty_deps_default = createRule({
|
|
|
133
140
|
},
|
|
134
141
|
name: RULE_NAME2,
|
|
135
142
|
create(context) {
|
|
143
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
136
144
|
const alias = decodeSettings(context.settings).additionalHooks?.useCallback ?? [];
|
|
137
145
|
return {
|
|
138
146
|
CallExpression(node) {
|
|
@@ -211,6 +219,7 @@ var ensure_use_memo_has_non_empty_deps_default = createRule({
|
|
|
211
219
|
},
|
|
212
220
|
name: RULE_NAME3,
|
|
213
221
|
create(context) {
|
|
222
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
214
223
|
const alias = decodeSettings(context.settings).additionalHooks?.useMemo ?? [];
|
|
215
224
|
return {
|
|
216
225
|
CallExpression(node) {
|
|
@@ -289,6 +298,7 @@ var no_direct_set_state_in_use_effect_default = createRule({
|
|
|
289
298
|
},
|
|
290
299
|
name: RULE_NAME4,
|
|
291
300
|
create(context) {
|
|
301
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
292
302
|
const settings = decodeSettings(context.settings);
|
|
293
303
|
const additionalHooks = settings.additionalHooks ?? {};
|
|
294
304
|
const isUseEffectCall = isReactHookCallWithNameAlias("useEffect", context, additionalHooks.useEffect ?? []);
|
|
@@ -459,6 +469,7 @@ var no_direct_set_state_in_use_layout_effect_default = createRule({
|
|
|
459
469
|
},
|
|
460
470
|
name: RULE_NAME5,
|
|
461
471
|
create(context) {
|
|
472
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
462
473
|
const settings = decodeSettings(context.settings);
|
|
463
474
|
const additionalHooks = settings.additionalHooks ?? {};
|
|
464
475
|
const isUseEffectCall = isReactHookCallWithNameAlias(
|
|
@@ -634,6 +645,7 @@ var prefer_use_state_lazy_initialization_default = createRule({
|
|
|
634
645
|
},
|
|
635
646
|
name: RULE_NAME6,
|
|
636
647
|
create(context) {
|
|
648
|
+
if (!context.sourceCode.text.includes("use")) return {};
|
|
637
649
|
const alias = decodeSettings(context.settings).additionalHooks?.useState ?? [];
|
|
638
650
|
return {
|
|
639
651
|
CallExpression(node) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-hooks-extra",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.2-beta.2",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Hooks related rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"eslint",
|
|
@@ -46,13 +46,13 @@
|
|
|
46
46
|
"@typescript-eslint/types": "^8.1.0",
|
|
47
47
|
"@typescript-eslint/utils": "^8.1.0",
|
|
48
48
|
"ts-pattern": "^5.3.1",
|
|
49
|
-
"@eslint-react/ast": "1.10.
|
|
50
|
-
"@eslint-react/core": "1.10.
|
|
51
|
-
"@eslint-react/jsx": "1.10.
|
|
52
|
-
"@eslint-react/
|
|
53
|
-
"@eslint-react/
|
|
54
|
-
"@eslint-react/
|
|
55
|
-
"@eslint-react/
|
|
49
|
+
"@eslint-react/ast": "1.10.2-beta.2",
|
|
50
|
+
"@eslint-react/core": "1.10.2-beta.2",
|
|
51
|
+
"@eslint-react/jsx": "1.10.2-beta.2",
|
|
52
|
+
"@eslint-react/shared": "1.10.2-beta.2",
|
|
53
|
+
"@eslint-react/tools": "1.10.2-beta.2",
|
|
54
|
+
"@eslint-react/var": "1.10.2-beta.2",
|
|
55
|
+
"@eslint-react/types": "1.10.2-beta.2"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
58
|
"@types/react": "^18.3.3",
|