eslint-plugin-react-x 5.0.1-next.1 → 5.0.2-beta.0
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/dist/index.js +38 -62
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -141,32 +141,10 @@ const rules$7 = {
|
|
|
141
141
|
//#endregion
|
|
142
142
|
//#region package.json
|
|
143
143
|
var name$6 = "eslint-plugin-react-x";
|
|
144
|
-
var version = "5.0.
|
|
144
|
+
var version = "5.0.2-beta.0";
|
|
145
145
|
|
|
146
146
|
//#endregion
|
|
147
|
-
//#region src/
|
|
148
|
-
function getDocsUrl(ruleName) {
|
|
149
|
-
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
150
|
-
}
|
|
151
|
-
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
152
|
-
|
|
153
|
-
//#endregion
|
|
154
|
-
//#region src/rules/component-hook-factories/component-hook-factories.ts
|
|
155
|
-
const RULE_NAME$48 = "component-hook-factories";
|
|
156
|
-
var component_hook_factories_default = createRule({
|
|
157
|
-
meta: {
|
|
158
|
-
type: "problem",
|
|
159
|
-
docs: { description: "Disallows higher order functions that define components or hooks inside them." },
|
|
160
|
-
messages: {
|
|
161
|
-
component: "Do not define component '{{name}}' inside a function. Components should be defined at the module level. Move it to the top level.",
|
|
162
|
-
hook: "Do not define hook '{{name}}' inside a function. Hooks should be defined at the module level. Move it to the top level."
|
|
163
|
-
},
|
|
164
|
-
schema: []
|
|
165
|
-
},
|
|
166
|
-
name: RULE_NAME$48,
|
|
167
|
-
create: create$48,
|
|
168
|
-
defaultOptions: []
|
|
169
|
-
});
|
|
147
|
+
//#region src/rules/component-hook-factories/lib.ts
|
|
170
148
|
/**
|
|
171
149
|
* Check if a function parameter has a type annotation that looks like a React component type.
|
|
172
150
|
* Matches types like ComponentType, React.ComponentType, FC, React.FC, etc.
|
|
@@ -203,13 +181,31 @@ function isHigherOrderComponent(fn) {
|
|
|
203
181
|
return false;
|
|
204
182
|
});
|
|
205
183
|
}
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
return ast.findParent(node, ast.isTestMockCallback) != null;
|
|
184
|
+
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/utils/create-rule.ts
|
|
187
|
+
function getDocsUrl(ruleName) {
|
|
188
|
+
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
212
189
|
}
|
|
190
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/rules/component-hook-factories/component-hook-factories.ts
|
|
194
|
+
const RULE_NAME$48 = "component-hook-factories";
|
|
195
|
+
var component_hook_factories_default = createRule({
|
|
196
|
+
meta: {
|
|
197
|
+
type: "problem",
|
|
198
|
+
docs: { description: "Disallows higher order functions that define components or hooks inside them." },
|
|
199
|
+
messages: {
|
|
200
|
+
component: "Do not define component '{{name}}' inside a function. Components should be defined at the module level. Move it to the top level.",
|
|
201
|
+
hook: "Do not define hook '{{name}}' inside a function. Hooks should be defined at the module level. Move it to the top level."
|
|
202
|
+
},
|
|
203
|
+
schema: []
|
|
204
|
+
},
|
|
205
|
+
name: RULE_NAME$48,
|
|
206
|
+
create: create$48,
|
|
207
|
+
defaultOptions: []
|
|
208
|
+
});
|
|
213
209
|
function create$48(context) {
|
|
214
210
|
const hint = core.FunctionComponentDetectionHint.DoNotIncludeJsxWithNumberValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithBooleanValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithNullValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithStringValue | core.FunctionComponentDetectionHint.DoNotIncludeJsxWithUndefinedValue | core.FunctionComponentDetectionHint.RequireBothSidesOfLogicalExpressionToBeJsx | core.FunctionComponentDetectionHint.RequireBothBranchesOfConditionalExpressionToBeJsx | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayPatternElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayExpressionElement | core.FunctionComponentDetectionHint.DoNotIncludeFunctionDefinedAsArrayMapCallback;
|
|
215
211
|
const fCollector = core.getFunctionComponentCollector(context, { hint });
|
|
@@ -224,7 +220,7 @@ function create$48(context) {
|
|
|
224
220
|
if (name == null) continue;
|
|
225
221
|
const parentFn = ast.findParent(node, ast.isFunction);
|
|
226
222
|
if (parentFn == null) continue;
|
|
227
|
-
if (
|
|
223
|
+
if (ast.findParent(node, ast.isTestMockCallback) != null) continue;
|
|
228
224
|
if (isHigherOrderComponent(parentFn)) continue;
|
|
229
225
|
if (reported.has(node)) continue;
|
|
230
226
|
context.report({
|
|
@@ -237,7 +233,7 @@ function create$48(context) {
|
|
|
237
233
|
for (const { name = "unknown", node } of cComponents) {
|
|
238
234
|
const parentFn = ast.findParent(node, ast.isFunction);
|
|
239
235
|
if (parentFn == null) continue;
|
|
240
|
-
if (
|
|
236
|
+
if (ast.findParent(node, ast.isTestMockCallback) != null) continue;
|
|
241
237
|
if (isHigherOrderComponent(parentFn)) continue;
|
|
242
238
|
context.report({
|
|
243
239
|
data: { name },
|
|
@@ -247,7 +243,7 @@ function create$48(context) {
|
|
|
247
243
|
}
|
|
248
244
|
for (const { name, node } of hooks) {
|
|
249
245
|
if (ast.findParent(node, ast.isFunction) == null) continue;
|
|
250
|
-
if (
|
|
246
|
+
if (ast.findParent(node, ast.isTestMockCallback) != null) continue;
|
|
251
247
|
if (reported.has(node)) continue;
|
|
252
248
|
context.report({
|
|
253
249
|
data: { name },
|
|
@@ -2615,10 +2611,10 @@ var no_missing_key_default = createRule({
|
|
|
2615
2611
|
create: create$22,
|
|
2616
2612
|
defaultOptions: []
|
|
2617
2613
|
});
|
|
2618
|
-
function create$22(
|
|
2614
|
+
function create$22(context) {
|
|
2619
2615
|
let inChildrenToArray = false;
|
|
2620
2616
|
function check(node) {
|
|
2621
|
-
if (node.type === AST_NODE_TYPES.JSXElement) return !hasAttribute(
|
|
2617
|
+
if (node.type === AST_NODE_TYPES.JSXElement) return !hasAttribute(context, node, "key") ? {
|
|
2622
2618
|
messageId: "default",
|
|
2623
2619
|
node
|
|
2624
2620
|
} : null;
|
|
@@ -2652,13 +2648,13 @@ function create$22(ctx) {
|
|
|
2652
2648
|
if (inChildrenToArray) return;
|
|
2653
2649
|
const elements = node.elements.filter(ast.is(AST_NODE_TYPES.JSXElement));
|
|
2654
2650
|
if (elements.length === 0) return;
|
|
2655
|
-
for (const el of elements) if (!hasAttribute(
|
|
2651
|
+
for (const el of elements) if (!hasAttribute(context, el, "key")) context.report({
|
|
2656
2652
|
messageId: "default",
|
|
2657
2653
|
node: el
|
|
2658
2654
|
});
|
|
2659
2655
|
},
|
|
2660
2656
|
CallExpression(node) {
|
|
2661
|
-
inChildrenToArray ||= core.isChildrenToArrayCall(
|
|
2657
|
+
inChildrenToArray ||= core.isChildrenToArrayCall(context, node);
|
|
2662
2658
|
if (inChildrenToArray) return;
|
|
2663
2659
|
if (node.callee.type !== AST_NODE_TYPES.MemberExpression) return;
|
|
2664
2660
|
if (node.callee.property.type !== AST_NODE_TYPES.Identifier) return;
|
|
@@ -2667,15 +2663,15 @@ function create$22(ctx) {
|
|
|
2667
2663
|
if (idx < 0) return;
|
|
2668
2664
|
const cb = node.arguments[idx];
|
|
2669
2665
|
if (!ast.isFunction(cb)) return;
|
|
2670
|
-
if (cb.body.type === AST_NODE_TYPES.BlockStatement) checkBlock(cb.body).forEach(report(
|
|
2671
|
-
else report(
|
|
2666
|
+
if (cb.body.type === AST_NODE_TYPES.BlockStatement) checkBlock(cb.body).forEach(report(context));
|
|
2667
|
+
else report(context)(checkExpr(cb.body));
|
|
2672
2668
|
},
|
|
2673
2669
|
"CallExpression:exit"(node) {
|
|
2674
|
-
if (core.isChildrenToArrayCall(
|
|
2670
|
+
if (core.isChildrenToArrayCall(context, node)) inChildrenToArray = false;
|
|
2675
2671
|
},
|
|
2676
2672
|
JSXFragment(node) {
|
|
2677
2673
|
if (inChildrenToArray) return;
|
|
2678
|
-
if (node.parent.type === AST_NODE_TYPES.ArrayExpression)
|
|
2674
|
+
if (node.parent.type === AST_NODE_TYPES.ArrayExpression) context.report({
|
|
2679
2675
|
messageId: "unexpectedFragmentSyntax",
|
|
2680
2676
|
node
|
|
2681
2677
|
});
|
|
@@ -3000,7 +2996,7 @@ function create$15(context) {
|
|
|
3000
2996
|
if (ast.isFunctionEmpty(node)) continue;
|
|
3001
2997
|
if (WELL_KNOWN_HOOKS.includes(name)) continue;
|
|
3002
2998
|
if (containsUseComments(context, node)) continue;
|
|
3003
|
-
if (ast.findParent(node, ast.
|
|
2999
|
+
if (ast.findParent(node, ast.isTestMockCallback) != null) continue;
|
|
3004
3000
|
context.report({
|
|
3005
3001
|
data: { name },
|
|
3006
3002
|
messageId: "default",
|
|
@@ -3591,20 +3587,15 @@ const IMPURE_FUNCS = new Map([
|
|
|
3591
3587
|
["globalThis", new Set([
|
|
3592
3588
|
"addEventListener",
|
|
3593
3589
|
"alert",
|
|
3594
|
-
"alert",
|
|
3595
3590
|
"blur",
|
|
3596
3591
|
"cancelAnimationFrame",
|
|
3597
3592
|
"cancelIdleCallback",
|
|
3598
3593
|
"clearInterval",
|
|
3599
|
-
"clearInterval",
|
|
3600
|
-
"clearTimeout",
|
|
3601
3594
|
"clearTimeout",
|
|
3602
3595
|
"close",
|
|
3603
3596
|
"confirm",
|
|
3604
|
-
"confirm",
|
|
3605
3597
|
"dispatchEvent",
|
|
3606
3598
|
"fetch",
|
|
3607
|
-
"fetch",
|
|
3608
3599
|
"focus",
|
|
3609
3600
|
"getComputedStyle",
|
|
3610
3601
|
"getSelection",
|
|
@@ -3613,11 +3604,8 @@ const IMPURE_FUNCS = new Map([
|
|
|
3613
3604
|
"moveTo",
|
|
3614
3605
|
"open",
|
|
3615
3606
|
"postMessage",
|
|
3616
|
-
"postMessage",
|
|
3617
3607
|
"print",
|
|
3618
3608
|
"prompt",
|
|
3619
|
-
"prompt",
|
|
3620
|
-
"queueMicrotask",
|
|
3621
3609
|
"queueMicrotask",
|
|
3622
3610
|
"removeEventListener",
|
|
3623
3611
|
"reportError",
|
|
@@ -3629,8 +3617,6 @@ const IMPURE_FUNCS = new Map([
|
|
|
3629
3617
|
"scrollBy",
|
|
3630
3618
|
"scrollTo",
|
|
3631
3619
|
"setInterval",
|
|
3632
|
-
"setInterval",
|
|
3633
|
-
"setTimeout",
|
|
3634
3620
|
"setTimeout",
|
|
3635
3621
|
"stop",
|
|
3636
3622
|
"structuredClone"
|
|
@@ -3734,20 +3720,15 @@ const IMPURE_FUNCS = new Map([
|
|
|
3734
3720
|
["window", new Set([
|
|
3735
3721
|
"addEventListener",
|
|
3736
3722
|
"alert",
|
|
3737
|
-
"alert",
|
|
3738
3723
|
"blur",
|
|
3739
3724
|
"cancelAnimationFrame",
|
|
3740
3725
|
"cancelIdleCallback",
|
|
3741
3726
|
"clearInterval",
|
|
3742
|
-
"clearInterval",
|
|
3743
|
-
"clearTimeout",
|
|
3744
3727
|
"clearTimeout",
|
|
3745
3728
|
"close",
|
|
3746
3729
|
"confirm",
|
|
3747
|
-
"confirm",
|
|
3748
3730
|
"dispatchEvent",
|
|
3749
3731
|
"fetch",
|
|
3750
|
-
"fetch",
|
|
3751
3732
|
"focus",
|
|
3752
3733
|
"getComputedStyle",
|
|
3753
3734
|
"getSelection",
|
|
@@ -3756,11 +3737,8 @@ const IMPURE_FUNCS = new Map([
|
|
|
3756
3737
|
"moveTo",
|
|
3757
3738
|
"open",
|
|
3758
3739
|
"postMessage",
|
|
3759
|
-
"postMessage",
|
|
3760
3740
|
"print",
|
|
3761
3741
|
"prompt",
|
|
3762
|
-
"prompt",
|
|
3763
|
-
"queueMicrotask",
|
|
3764
3742
|
"queueMicrotask",
|
|
3765
3743
|
"removeEventListener",
|
|
3766
3744
|
"reportError",
|
|
@@ -3772,8 +3750,6 @@ const IMPURE_FUNCS = new Map([
|
|
|
3772
3750
|
"scrollBy",
|
|
3773
3751
|
"scrollTo",
|
|
3774
3752
|
"setInterval",
|
|
3775
|
-
"setInterval",
|
|
3776
|
-
"setTimeout",
|
|
3777
3753
|
"setTimeout",
|
|
3778
3754
|
"stop",
|
|
3779
3755
|
"structuredClone"
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-x",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2-beta.0",
|
|
4
4
|
"description": "A set of composable ESLint rules for libraries and frameworks that use React as a UI runtime.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -45,11 +45,11 @@
|
|
|
45
45
|
"string-ts": "^2.3.1",
|
|
46
46
|
"ts-api-utils": "^2.5.0",
|
|
47
47
|
"ts-pattern": "^5.9.0",
|
|
48
|
-
"@eslint-react/ast": "5.0.
|
|
49
|
-
"@eslint-react/core": "5.0.
|
|
50
|
-
"@eslint-react/jsx": "5.0.
|
|
51
|
-
"@eslint-react/shared": "5.0.
|
|
52
|
-
"@eslint-react/var": "5.0.
|
|
48
|
+
"@eslint-react/ast": "5.0.2-beta.0",
|
|
49
|
+
"@eslint-react/core": "5.0.2-beta.0",
|
|
50
|
+
"@eslint-react/jsx": "5.0.2-beta.0",
|
|
51
|
+
"@eslint-react/shared": "5.0.2-beta.0",
|
|
52
|
+
"@eslint-react/var": "5.0.2-beta.0"
|
|
53
53
|
},
|
|
54
54
|
"devDependencies": {
|
|
55
55
|
"@types/react": "^19.2.14",
|