eslint-plugin-react-jsx 5.30.0-beta.5 → 5.30.0-beta.7
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 +63 -72
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
|
|
2
2
|
import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
|
|
3
|
-
import { getText } from "@eslint-react/eslint";
|
|
4
|
-
import { collapseMultilineText, findAttribute,
|
|
5
|
-
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
3
|
+
import { complete, getText } from "@eslint-react/eslint";
|
|
4
|
+
import { collapseMultilineText, findAttribute, findCreateElementProp, getChildren, getElementFullType, hasAnyAttribute, hasMeaningfulChildren, isFragmentElement, isHostElement, isMeaningfulChild, isPlainAttribute, isWhitespaceText, parseCreateElementCall } from "@eslint-react/jsx";
|
|
6
5
|
import { Check } from "@eslint-react/ast";
|
|
6
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
7
7
|
import * as core from "@eslint-react/core";
|
|
8
8
|
import ts from "typescript";
|
|
9
9
|
// \0rolldown/runtime.js
|
|
@@ -19,7 +19,7 @@ var __exportAll = (all, no_symbols) => {
|
|
|
19
19
|
};
|
|
20
20
|
// package.json
|
|
21
21
|
var name$2 = "eslint-plugin-react-jsx";
|
|
22
|
-
var version = "5.30.0-beta.
|
|
22
|
+
var version = "5.30.0-beta.7";
|
|
23
23
|
// src/utils/create-rule.ts
|
|
24
24
|
function getDocsUrl(ruleName) {
|
|
25
25
|
return `https://eslint-react.xyz/docs/rules/jsx-${ruleName}`;
|
|
@@ -50,24 +50,18 @@ var no_children_prop_with_children_default = createRule({
|
|
|
50
50
|
function create$7(context) {
|
|
51
51
|
return {
|
|
52
52
|
CallExpression(node) {
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
53
|
+
const call = parseCreateElementCall(context, node);
|
|
54
|
+
if (call == null) return;
|
|
55
|
+
const prop = findCreateElementProp(context, call, "children");
|
|
56
|
+
if (prop == null || call.childrenArguments.length === 0) return;
|
|
56
57
|
context.report({
|
|
57
58
|
messageId: "default",
|
|
58
59
|
node: prop
|
|
59
60
|
});
|
|
60
61
|
},
|
|
61
62
|
JSXElement(node) {
|
|
62
|
-
const prop = findAttribute(
|
|
63
|
-
if (prop == null || !
|
|
64
|
-
if (prop.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
65
|
-
context.report({
|
|
66
|
-
messageId: "default",
|
|
67
|
-
node: prop
|
|
68
|
-
});
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
63
|
+
const prop = findAttribute(node, "children");
|
|
64
|
+
if (prop == null || !hasMeaningfulChildren(node)) return;
|
|
71
65
|
context.report({
|
|
72
66
|
messageId: "default",
|
|
73
67
|
node: prop,
|
|
@@ -107,25 +101,18 @@ var no_children_prop_default = createRule({
|
|
|
107
101
|
function create$6(context) {
|
|
108
102
|
return {
|
|
109
103
|
CallExpression(node) {
|
|
110
|
-
const
|
|
111
|
-
if (
|
|
112
|
-
|
|
104
|
+
const call = parseCreateElementCall(context, node);
|
|
105
|
+
if (call == null) return;
|
|
106
|
+
const prop = findCreateElementProp(context, call, "children");
|
|
107
|
+
if (prop == null || call.childrenArguments.length > 0) return;
|
|
113
108
|
context.report({
|
|
114
109
|
messageId: "default",
|
|
115
110
|
node: prop
|
|
116
111
|
});
|
|
117
112
|
},
|
|
118
113
|
JSXElement(node) {
|
|
119
|
-
const prop = findAttribute(
|
|
120
|
-
if (prop == null) return;
|
|
121
|
-
if (hasChildren(node)) return;
|
|
122
|
-
if (prop.type !== AST_NODE_TYPES.JSXAttribute) {
|
|
123
|
-
context.report({
|
|
124
|
-
messageId: "default",
|
|
125
|
-
node: prop
|
|
126
|
-
});
|
|
127
|
-
return;
|
|
128
|
-
}
|
|
114
|
+
const prop = findAttribute(node, "children");
|
|
115
|
+
if (prop == null || hasMeaningfulChildren(node)) return;
|
|
129
116
|
const childrenText = getChildrenText(context, prop);
|
|
130
117
|
if (childrenText == null) {
|
|
131
118
|
context.report({
|
|
@@ -259,7 +246,7 @@ function not(predicate) {
|
|
|
259
246
|
return (data) => !predicate(data);
|
|
260
247
|
}
|
|
261
248
|
dual(2, (a, b) => (data) => a(data) && b(data));
|
|
262
|
-
|
|
249
|
+
dual(2, (a, b) => (data) => a(data) || b(data));
|
|
263
250
|
dual(2, (a, b) => (data) => a(data) !== b(data));
|
|
264
251
|
dual(2, (a, b) => (data) => a(data) === b(data));
|
|
265
252
|
dual(2, (antecedent, consequent) => (data) => !antecedent(data) || consequent(data));
|
|
@@ -301,7 +288,7 @@ function create$4(context) {
|
|
|
301
288
|
const { jsx } = core.getJSXConfig(context);
|
|
302
289
|
if (jsx !== ts.JsxEmit.ReactJSX && jsx !== ts.JsxEmit.ReactJSXDev) return {};
|
|
303
290
|
return { JSXOpeningElement(node) {
|
|
304
|
-
for (const n of dropWhile(node.attributes, not(Check.isJSXSpreadAttribute)).filter(
|
|
291
|
+
for (const n of dropWhile(node.attributes, not(Check.isJSXSpreadAttribute)).filter(isPlainAttribute("key"))) context.report({
|
|
305
292
|
messageId: "default",
|
|
306
293
|
node: n
|
|
307
294
|
});
|
|
@@ -324,39 +311,44 @@ var no_leaked_dollar_default = createRule({
|
|
|
324
311
|
});
|
|
325
312
|
function create$3(context) {
|
|
326
313
|
if (!context.sourceCode.text.includes("$")) return {};
|
|
327
|
-
function visit(node) {
|
|
328
|
-
for (const [index, child] of node.children.entries()) {
|
|
329
|
-
if (child.type !== AST_NODE_TYPES.JSXText || !child.value.endsWith("$")) continue;
|
|
330
|
-
if (node.children[index + 1]?.type !== AST_NODE_TYPES.JSXExpressionContainer) continue;
|
|
331
|
-
if (child.value.trim() === "$" && node.children.every((sibling, siblingIndex) => siblingIndex === index || siblingIndex === index + 1 || isNonSubstantiveChild(sibling))) continue;
|
|
332
|
-
if (!getText(context, child).endsWith("$")) continue;
|
|
333
|
-
const dollarStart = child.range[1] - 1;
|
|
334
|
-
const dollarEnd = child.range[1];
|
|
335
|
-
context.report({
|
|
336
|
-
loc: {
|
|
337
|
-
end: context.sourceCode.getLocFromIndex(dollarEnd),
|
|
338
|
-
start: context.sourceCode.getLocFromIndex(dollarStart)
|
|
339
|
-
},
|
|
340
|
-
messageId: "default",
|
|
341
|
-
node: child,
|
|
342
|
-
suggest: [{
|
|
343
|
-
fix(fixer) {
|
|
344
|
-
return fixer.removeRange([dollarStart, dollarEnd]);
|
|
345
|
-
},
|
|
346
|
-
messageId: "suggest"
|
|
347
|
-
}]
|
|
348
|
-
});
|
|
349
|
-
}
|
|
350
|
-
}
|
|
351
314
|
return {
|
|
352
|
-
JSXElement
|
|
353
|
-
|
|
315
|
+
JSXElement(node) {
|
|
316
|
+
visitForLeakedDollar(context, node);
|
|
317
|
+
},
|
|
318
|
+
JSXFragment(node) {
|
|
319
|
+
visitForLeakedDollar(context, node);
|
|
320
|
+
}
|
|
354
321
|
};
|
|
355
322
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
323
|
+
function visitForLeakedDollar(context, node) {
|
|
324
|
+
let meaningfulChildren = null;
|
|
325
|
+
for (const [index, child] of node.children.entries()) {
|
|
326
|
+
if (child.type !== AST_NODE_TYPES.JSXText || !child.value.endsWith("$")) continue;
|
|
327
|
+
const next = node.children[index + 1];
|
|
328
|
+
if (next?.type !== AST_NODE_TYPES.JSXExpressionContainer) continue;
|
|
329
|
+
meaningfulChildren ??= node.children.filter(isMeaningfulChild).length;
|
|
330
|
+
if (isIsolatedDollar(child, next, meaningfulChildren)) continue;
|
|
331
|
+
if (!getText(context, child).endsWith("$")) continue;
|
|
332
|
+
const dollarStart = child.range[1] - 1;
|
|
333
|
+
const dollarEnd = child.range[1];
|
|
334
|
+
context.report({
|
|
335
|
+
loc: {
|
|
336
|
+
end: context.sourceCode.getLocFromIndex(dollarEnd),
|
|
337
|
+
start: context.sourceCode.getLocFromIndex(dollarStart)
|
|
338
|
+
},
|
|
339
|
+
messageId: "default",
|
|
340
|
+
node: child,
|
|
341
|
+
suggest: [{
|
|
342
|
+
fix(fixer) {
|
|
343
|
+
return fixer.removeRange([dollarStart, dollarEnd]);
|
|
344
|
+
},
|
|
345
|
+
messageId: "suggest"
|
|
346
|
+
}]
|
|
347
|
+
});
|
|
348
|
+
}
|
|
349
|
+
}
|
|
350
|
+
function isIsolatedDollar(child, next, meaningfulChildren) {
|
|
351
|
+
return child.value.trim() === "$" && meaningfulChildren === 1 + (isMeaningfulChild(next) ? 1 : 0);
|
|
360
352
|
}
|
|
361
353
|
var no_leaked_semicolon_default = createRule({
|
|
362
354
|
meta: {
|
|
@@ -401,12 +393,12 @@ var no_namespace_default = createRule({
|
|
|
401
393
|
});
|
|
402
394
|
function create$1(context) {
|
|
403
395
|
return { JSXElement(node) {
|
|
404
|
-
const name =
|
|
405
|
-
if (
|
|
396
|
+
const { name } = node.openingElement;
|
|
397
|
+
if (name.type !== AST_NODE_TYPES.JSXNamespacedName) return;
|
|
406
398
|
context.report({
|
|
407
|
-
data: { name },
|
|
399
|
+
data: { name: getElementFullType(node) },
|
|
408
400
|
messageId: "default",
|
|
409
|
-
node:
|
|
401
|
+
node: name
|
|
410
402
|
});
|
|
411
403
|
} };
|
|
412
404
|
}
|
|
@@ -442,16 +434,13 @@ var no_useless_fragment_default = createRule({
|
|
|
442
434
|
name: RULE_NAME,
|
|
443
435
|
create
|
|
444
436
|
});
|
|
445
|
-
function create(context
|
|
446
|
-
const options =
|
|
447
|
-
allowEmptyFragment: option.allowEmptyFragment ?? false,
|
|
448
|
-
allowExpressions: option.allowExpressions ?? true
|
|
449
|
-
};
|
|
437
|
+
function create(context) {
|
|
438
|
+
const options = complete(context.options[0], defaultOptions[0]);
|
|
450
439
|
const { jsxFragmentFactory } = core.getJSXConfig(context);
|
|
451
440
|
return {
|
|
452
441
|
JSXElement(node) {
|
|
453
442
|
if (!isFragmentElement(node, jsxFragmentFactory)) return;
|
|
454
|
-
if (
|
|
443
|
+
if (hasIdentityAttribute(node)) return;
|
|
455
444
|
visitFragment(context, node, options);
|
|
456
445
|
},
|
|
457
446
|
JSXFragment(node) {
|
|
@@ -459,6 +448,9 @@ function create(context, [option]) {
|
|
|
459
448
|
}
|
|
460
449
|
};
|
|
461
450
|
}
|
|
451
|
+
function hasIdentityAttribute(node) {
|
|
452
|
+
return node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute) || hasAnyAttribute(node, ["key", "ref"]);
|
|
453
|
+
}
|
|
462
454
|
function visitFragment(context, node, options) {
|
|
463
455
|
const reasons = [];
|
|
464
456
|
if (isHostElement(node.parent)) reasons.push("placed inside a host component");
|
|
@@ -484,7 +476,6 @@ function isContentUseless(node, options) {
|
|
|
484
476
|
return true;
|
|
485
477
|
}
|
|
486
478
|
function isSafeToFix(node) {
|
|
487
|
-
if (node.type === AST_NODE_TYPES.JSXElement && node.openingElement.attributes.some((attr) => attr.type === AST_NODE_TYPES.JSXSpreadAttribute)) return false;
|
|
488
479
|
if (Check.isJSXElementOrFragment(node.parent)) return isHostElement(node.parent);
|
|
489
480
|
if (!node.children.some((child) => Check.isJSXElementOrFragment(child))) return false;
|
|
490
481
|
return node.children.every((child) => {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-jsx",
|
|
3
|
-
"version": "5.30.0-beta.
|
|
3
|
+
"version": "5.30.0-beta.7",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Flavored JSX rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,11 +37,11 @@
|
|
|
37
37
|
"dist"
|
|
38
38
|
],
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@eslint-react/ast": "5.30.0-beta.
|
|
41
|
-
"@eslint-react/core": "5.30.0-beta.
|
|
42
|
-
"@eslint-react/eslint": "5.30.0-beta.
|
|
43
|
-
"@eslint-react/jsx": "5.30.0-beta.
|
|
44
|
-
"@eslint-react/shared": "5.30.0-beta.
|
|
40
|
+
"@eslint-react/ast": "5.30.0-beta.7",
|
|
41
|
+
"@eslint-react/core": "5.30.0-beta.7",
|
|
42
|
+
"@eslint-react/eslint": "5.30.0-beta.7",
|
|
43
|
+
"@eslint-react/jsx": "5.30.0-beta.7",
|
|
44
|
+
"@eslint-react/shared": "5.30.0-beta.7",
|
|
45
45
|
"@typescript-eslint/types": "^8.72.1",
|
|
46
46
|
"@typescript-eslint/utils": "^8.72.1"
|
|
47
47
|
},
|