eslint-plugin-react-jsx 5.30.0-beta.8 → 5.30.0-rc.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 +33 -34
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
|
|
2
2
|
import * as ESLintUtils from "@typescript-eslint/utils/eslint-utils";
|
|
3
|
-
import {
|
|
3
|
+
import { getText } from "@eslint-react/eslint";
|
|
4
4
|
import { collapseMultilineText, findAttribute, findCreateElementProp, getChildren, getElementFullType, hasAnyAttribute, hasMeaningfulChildren, isFragmentElement, isHostElement, isMeaningfulChild, isPlainAttribute, isWhitespaceText, parseCreateElementCall } from "@eslint-react/jsx";
|
|
5
5
|
import { Check } from "@eslint-react/ast";
|
|
6
6
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
@@ -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-
|
|
22
|
+
var version = "5.30.0-rc.0";
|
|
23
23
|
// src/utils/create-rule.ts
|
|
24
24
|
function getDocsUrl(ruleName) {
|
|
25
25
|
return `https://eslint-react.xyz/docs/rules/jsx-${ruleName}`;
|
|
@@ -113,8 +113,9 @@ function create$6(context) {
|
|
|
113
113
|
JSXElement(node) {
|
|
114
114
|
const prop = findAttribute(node, "children");
|
|
115
115
|
if (prop == null || hasMeaningfulChildren(node)) return;
|
|
116
|
+
const hasFollowingSpread = node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute && a.range[0] > prop.range[0]);
|
|
116
117
|
const childrenText = getChildrenText(context, prop);
|
|
117
|
-
if (childrenText == null) {
|
|
118
|
+
if (childrenText == null || hasFollowingSpread) {
|
|
118
119
|
context.report({
|
|
119
120
|
messageId: "default",
|
|
120
121
|
node: prop
|
|
@@ -368,7 +369,11 @@ var no_leaked_semicolon_default = createRule({
|
|
|
368
369
|
function create$2(context) {
|
|
369
370
|
return { JSXText(node) {
|
|
370
371
|
if (!Check.isJSXElementOrFragment(node.parent)) return;
|
|
371
|
-
|
|
372
|
+
const text = getText(context, node);
|
|
373
|
+
const children = node.parent.children;
|
|
374
|
+
const previous = children.at(-2);
|
|
375
|
+
const isSameLineLeak = children.at(-1) === node && previous != null && Check.isJSXElementOrFragment(previous) && /^;+[ \t]*$/u.test(text);
|
|
376
|
+
if (!/^;+[ \t]*(?:\r\n|\r|\n)/u.test(text) && !isSameLineLeak) return;
|
|
372
377
|
context.report({
|
|
373
378
|
messageId: "default",
|
|
374
379
|
node,
|
|
@@ -402,59 +407,54 @@ function create$1(context) {
|
|
|
402
407
|
});
|
|
403
408
|
} };
|
|
404
409
|
}
|
|
405
|
-
// src/rules/no-useless-fragment/no-useless-fragment.ts
|
|
406
|
-
const RULE_NAME = "no-useless-fragment";
|
|
407
|
-
const defaultOptions = [{
|
|
408
|
-
allowEmptyFragment: false,
|
|
409
|
-
allowExpressions: true
|
|
410
|
-
}];
|
|
411
|
-
const schema = [{
|
|
412
|
-
type: "object",
|
|
413
|
-
additionalProperties: false,
|
|
414
|
-
properties: {
|
|
415
|
-
allowEmptyFragment: {
|
|
416
|
-
type: "boolean",
|
|
417
|
-
description: "Allow empty fragments"
|
|
418
|
-
},
|
|
419
|
-
allowExpressions: {
|
|
420
|
-
type: "boolean",
|
|
421
|
-
description: "Allow fragments with a single expression child"
|
|
422
|
-
}
|
|
423
|
-
}
|
|
424
|
-
}];
|
|
425
410
|
var no_useless_fragment_default = createRule({
|
|
426
411
|
meta: {
|
|
427
412
|
type: "suggestion",
|
|
428
|
-
defaultOptions: [
|
|
413
|
+
defaultOptions: [{}],
|
|
429
414
|
docs: { description: "Disallows useless fragment elements." },
|
|
430
415
|
fixable: "code",
|
|
431
416
|
messages: { default: "A fragment {{reason}} is useless." },
|
|
432
|
-
schema
|
|
417
|
+
schema: [{
|
|
418
|
+
type: "object",
|
|
419
|
+
additionalProperties: false,
|
|
420
|
+
properties: {
|
|
421
|
+
allowEmptyFragment: {
|
|
422
|
+
type: "boolean",
|
|
423
|
+
description: "Allow empty fragments"
|
|
424
|
+
},
|
|
425
|
+
allowExpressions: {
|
|
426
|
+
type: "boolean",
|
|
427
|
+
description: "Allow fragments with a single expression child"
|
|
428
|
+
}
|
|
429
|
+
}
|
|
430
|
+
}]
|
|
433
431
|
},
|
|
434
|
-
name:
|
|
432
|
+
name: "no-useless-fragment",
|
|
435
433
|
create
|
|
436
434
|
});
|
|
437
435
|
function create(context) {
|
|
438
|
-
const options =
|
|
436
|
+
const options = context.options[0] ?? {};
|
|
437
|
+
const allowEmptyFragment = options.allowEmptyFragment ?? false;
|
|
438
|
+
const allowExpressions = options.allowExpressions ?? true;
|
|
439
439
|
const { jsxFragmentFactory } = core.getJSXConfig(context);
|
|
440
440
|
return {
|
|
441
441
|
JSXElement(node) {
|
|
442
442
|
if (!isFragmentElement(node, jsxFragmentFactory)) return;
|
|
443
443
|
if (hasIdentityAttribute(node)) return;
|
|
444
|
-
visitFragment(context, node,
|
|
444
|
+
visitFragment(context, node, allowEmptyFragment, allowExpressions);
|
|
445
445
|
},
|
|
446
446
|
JSXFragment(node) {
|
|
447
|
-
visitFragment(context, node,
|
|
447
|
+
visitFragment(context, node, allowEmptyFragment, allowExpressions);
|
|
448
448
|
}
|
|
449
449
|
};
|
|
450
450
|
}
|
|
451
451
|
function hasIdentityAttribute(node) {
|
|
452
452
|
return node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute) || hasAnyAttribute(node, ["key", "ref"]);
|
|
453
453
|
}
|
|
454
|
-
function visitFragment(context, node,
|
|
454
|
+
function visitFragment(context, node, allowEmptyFragment, allowExpressions) {
|
|
455
455
|
const reasons = [];
|
|
456
456
|
if (isHostElement(node.parent)) reasons.push("placed inside a host component");
|
|
457
|
-
if (isContentUseless(node,
|
|
457
|
+
if (isContentUseless(node, allowEmptyFragment, allowExpressions)) reasons.push("contains less than two children");
|
|
458
458
|
if (reasons.length === 0) return;
|
|
459
459
|
const fix = buildFix(context, node);
|
|
460
460
|
for (const reason of reasons) context.report({
|
|
@@ -464,8 +464,7 @@ function visitFragment(context, node, options) {
|
|
|
464
464
|
node
|
|
465
465
|
});
|
|
466
466
|
}
|
|
467
|
-
function isContentUseless(node,
|
|
468
|
-
const { allowEmptyFragment, allowExpressions } = options;
|
|
467
|
+
function isContentUseless(node, allowEmptyFragment, allowExpressions) {
|
|
469
468
|
if (node.children.length === 0) return !allowEmptyFragment;
|
|
470
469
|
const insideJSX = Check.isJSXElementOrFragment(node.parent);
|
|
471
470
|
if (allowExpressions && !insideJSX && node.children.length === 1 && node.children[0]?.type === AST_NODE_TYPES.JSXText) return false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-jsx",
|
|
3
|
-
"version": "5.30.0-
|
|
3
|
+
"version": "5.30.0-rc.0",
|
|
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-
|
|
41
|
-
"@eslint-react/core": "5.30.0-
|
|
42
|
-
"@eslint-react/eslint": "5.30.0-
|
|
43
|
-
"@eslint-react/jsx": "5.30.0-
|
|
44
|
-
"@eslint-react/shared": "5.30.0-
|
|
40
|
+
"@eslint-react/ast": "5.30.0-rc.0",
|
|
41
|
+
"@eslint-react/core": "5.30.0-rc.0",
|
|
42
|
+
"@eslint-react/eslint": "5.30.0-rc.0",
|
|
43
|
+
"@eslint-react/jsx": "5.30.0-rc.0",
|
|
44
|
+
"@eslint-react/shared": "5.30.0-rc.0",
|
|
45
45
|
"@typescript-eslint/types": "^8.72.1",
|
|
46
46
|
"@typescript-eslint/utils": "^8.72.1"
|
|
47
47
|
},
|
|
@@ -54,8 +54,8 @@
|
|
|
54
54
|
"@types/react": "^19.3.0",
|
|
55
55
|
"@types/react-dom": "^19.3.0",
|
|
56
56
|
"dedent": "^1.7.2",
|
|
57
|
-
"eslint": "^10.
|
|
58
|
-
"tsdown": "^0.23.
|
|
57
|
+
"eslint": "^10.14.0",
|
|
58
|
+
"tsdown": "^0.23.5",
|
|
59
59
|
"typescript": "6.0.3"
|
|
60
60
|
},
|
|
61
61
|
"peerDependencies": {
|