eslint-plugin-react-jsx 5.30.0-beta.0 → 5.30.0-beta.10
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 +86 -101
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
|
|
2
2
|
import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
|
|
3
|
-
import * as core from "@eslint-react/core";
|
|
4
3
|
import { getText } from "@eslint-react/eslint";
|
|
5
|
-
import { collapseMultilineText, findAttribute, getChildren, getElementFullType, hasAnyAttribute,
|
|
6
|
-
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
4
|
+
import { collapseMultilineText, findAttribute, findCreateElementProp, getChildren, getElementFullType, hasAnyAttribute, hasMeaningfulChildren, isFragmentElement, isHostElement, isMeaningfulChild, isPlainAttribute, isWhitespaceText, parseCreateElementCall } from "@eslint-react/jsx";
|
|
7
5
|
import { Check } from "@eslint-react/ast";
|
|
6
|
+
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
7
|
+
import * as core from "@eslint-react/core";
|
|
8
8
|
import ts from "typescript";
|
|
9
9
|
// \0rolldown/runtime.js
|
|
10
10
|
var __defProp = Object.defineProperty;
|
|
@@ -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.10";
|
|
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,68 +393,63 @@ 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
|
}
|
|
413
|
-
// src/rules/no-useless-fragment/no-useless-fragment.ts
|
|
414
|
-
const RULE_NAME = "no-useless-fragment";
|
|
415
|
-
const defaultOptions = [{
|
|
416
|
-
allowEmptyFragment: false,
|
|
417
|
-
allowExpressions: true
|
|
418
|
-
}];
|
|
419
|
-
const schema = [{
|
|
420
|
-
type: "object",
|
|
421
|
-
additionalProperties: false,
|
|
422
|
-
properties: {
|
|
423
|
-
allowEmptyFragment: {
|
|
424
|
-
type: "boolean",
|
|
425
|
-
description: "Allow empty fragments"
|
|
426
|
-
},
|
|
427
|
-
allowExpressions: {
|
|
428
|
-
type: "boolean",
|
|
429
|
-
description: "Allow fragments with a single expression child"
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}];
|
|
433
405
|
var no_useless_fragment_default = createRule({
|
|
434
406
|
meta: {
|
|
435
407
|
type: "suggestion",
|
|
436
|
-
defaultOptions: [
|
|
408
|
+
defaultOptions: [{}],
|
|
437
409
|
docs: { description: "Disallows useless fragment elements." },
|
|
438
410
|
fixable: "code",
|
|
439
411
|
messages: { default: "A fragment {{reason}} is useless." },
|
|
440
|
-
schema
|
|
412
|
+
schema: [{
|
|
413
|
+
type: "object",
|
|
414
|
+
additionalProperties: false,
|
|
415
|
+
properties: {
|
|
416
|
+
allowEmptyFragment: {
|
|
417
|
+
type: "boolean",
|
|
418
|
+
description: "Allow empty fragments"
|
|
419
|
+
},
|
|
420
|
+
allowExpressions: {
|
|
421
|
+
type: "boolean",
|
|
422
|
+
description: "Allow fragments with a single expression child"
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
}]
|
|
441
426
|
},
|
|
442
|
-
name:
|
|
427
|
+
name: "no-useless-fragment",
|
|
443
428
|
create
|
|
444
429
|
});
|
|
445
|
-
function create(context
|
|
446
|
-
const options = {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
};
|
|
430
|
+
function create(context) {
|
|
431
|
+
const options = context.options[0] ?? {};
|
|
432
|
+
const allowEmptyFragment = options.allowEmptyFragment ?? false;
|
|
433
|
+
const allowExpressions = options.allowExpressions ?? true;
|
|
450
434
|
const { jsxFragmentFactory } = core.getJSXConfig(context);
|
|
451
435
|
return {
|
|
452
436
|
JSXElement(node) {
|
|
453
437
|
if (!isFragmentElement(node, jsxFragmentFactory)) return;
|
|
454
|
-
if (
|
|
455
|
-
visitFragment(context, node,
|
|
438
|
+
if (hasIdentityAttribute(node)) return;
|
|
439
|
+
visitFragment(context, node, allowEmptyFragment, allowExpressions);
|
|
456
440
|
},
|
|
457
441
|
JSXFragment(node) {
|
|
458
|
-
visitFragment(context, node,
|
|
442
|
+
visitFragment(context, node, allowEmptyFragment, allowExpressions);
|
|
459
443
|
}
|
|
460
444
|
};
|
|
461
445
|
}
|
|
462
|
-
function
|
|
446
|
+
function hasIdentityAttribute(node) {
|
|
447
|
+
return node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute) || hasAnyAttribute(node, ["key", "ref"]);
|
|
448
|
+
}
|
|
449
|
+
function visitFragment(context, node, allowEmptyFragment, allowExpressions) {
|
|
463
450
|
const reasons = [];
|
|
464
451
|
if (isHostElement(node.parent)) reasons.push("placed inside a host component");
|
|
465
|
-
if (isContentUseless(node,
|
|
452
|
+
if (isContentUseless(node, allowEmptyFragment, allowExpressions)) reasons.push("contains less than two children");
|
|
466
453
|
if (reasons.length === 0) return;
|
|
467
454
|
const fix = buildFix(context, node);
|
|
468
455
|
for (const reason of reasons) context.report({
|
|
@@ -472,8 +459,7 @@ function visitFragment(context, node, options) {
|
|
|
472
459
|
node
|
|
473
460
|
});
|
|
474
461
|
}
|
|
475
|
-
function isContentUseless(node,
|
|
476
|
-
const { allowEmptyFragment, allowExpressions } = options;
|
|
462
|
+
function isContentUseless(node, allowEmptyFragment, allowExpressions) {
|
|
477
463
|
if (node.children.length === 0) return !allowEmptyFragment;
|
|
478
464
|
const insideJSX = Check.isJSXElementOrFragment(node.parent);
|
|
479
465
|
if (allowExpressions && !insideJSX && node.children.length === 1 && node.children[0]?.type === AST_NODE_TYPES.JSXText) return false;
|
|
@@ -484,7 +470,6 @@ function isContentUseless(node, options) {
|
|
|
484
470
|
return true;
|
|
485
471
|
}
|
|
486
472
|
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
473
|
if (Check.isJSXElementOrFragment(node.parent)) return isHostElement(node.parent);
|
|
489
474
|
if (!node.children.some((child) => Check.isJSXElementOrFragment(child))) return false;
|
|
490
475
|
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.10",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Flavored JSX rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -37,13 +37,13 @@
|
|
|
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.
|
|
45
|
-
"@typescript-eslint/types": "^8.72.
|
|
46
|
-
"@typescript-eslint/utils": "^8.72.
|
|
40
|
+
"@eslint-react/ast": "5.30.0-beta.10",
|
|
41
|
+
"@eslint-react/core": "5.30.0-beta.10",
|
|
42
|
+
"@eslint-react/eslint": "5.30.0-beta.10",
|
|
43
|
+
"@eslint-react/jsx": "5.30.0-beta.10",
|
|
44
|
+
"@eslint-react/shared": "5.30.0-beta.10",
|
|
45
|
+
"@typescript-eslint/types": "^8.72.1",
|
|
46
|
+
"@typescript-eslint/utils": "^8.72.1"
|
|
47
47
|
},
|
|
48
48
|
"devDependencies": {
|
|
49
49
|
"@local/configs": "0.0.0",
|