eslint-plugin-react-x 5.0.1-next.2 → 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 -42
- 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",
|
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/
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/
|
|
51
|
-
"@eslint-react/
|
|
52
|
-
"@eslint-react/
|
|
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",
|