eslint-plugin-react-jsx 5.0.1-next.1 → 5.0.2-next.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 +84 -65
- package/package.json +6 -6
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DEFAULT_ESLINT_REACT_SETTINGS, defineRuleListener } from "@eslint-react/shared";
|
|
2
2
|
import { JsxEmit, findAttribute, getChildren, getElementFullType, getJsxConfig, hasAnyAttribute, hasChildren, isFragmentElement, isHostElement, isWhitespaceText } from "@eslint-react/jsx";
|
|
3
3
|
import { AST_NODE_TYPES } from "@typescript-eslint/types";
|
|
4
|
-
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
5
4
|
import * as ast from "@eslint-react/ast";
|
|
5
|
+
import { ESLintUtils } from "@typescript-eslint/utils";
|
|
6
6
|
|
|
7
7
|
//#region \0rolldown/runtime.js
|
|
8
8
|
var __defProp = Object.defineProperty;
|
|
@@ -23,37 +23,17 @@ var __exportAll = (all, no_symbols) => {
|
|
|
23
23
|
//#endregion
|
|
24
24
|
//#region package.json
|
|
25
25
|
var name$2 = "eslint-plugin-react-jsx";
|
|
26
|
-
var version = "5.0.
|
|
27
|
-
|
|
28
|
-
//#endregion
|
|
29
|
-
//#region src/utils/create-rule.ts
|
|
30
|
-
function getDocsUrl(ruleName) {
|
|
31
|
-
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
32
|
-
}
|
|
33
|
-
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
26
|
+
var version = "5.0.2-next.0";
|
|
34
27
|
|
|
35
28
|
//#endregion
|
|
36
|
-
//#region src/
|
|
37
|
-
/**
|
|
38
|
-
* Trim leading / trailing whitespace the same way React does when rendering
|
|
39
|
-
* JSX text. Whitespace that contains a newline is stripped entirely;
|
|
40
|
-
* whitespace that stays on the same line is preserved.
|
|
41
|
-
* @param text The JSX text to trim.
|
|
42
|
-
*/
|
|
43
|
-
function trimLikeReact(text) {
|
|
44
|
-
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
45
|
-
const trailingSpaces = /\s*$/.exec(text)?.[0] ?? "";
|
|
46
|
-
const start = leadingSpaces.includes("\n") ? leadingSpaces.length : 0;
|
|
47
|
-
const end = trailingSpaces.includes("\n") ? text.length - trailingSpaces.length : text.length;
|
|
48
|
-
return text.slice(start, end);
|
|
49
|
-
}
|
|
29
|
+
//#region src/rules/no-children-prop-with-children/lib.ts
|
|
50
30
|
/**
|
|
51
31
|
* Compute the removal range for a JSX attribute, consuming any leading
|
|
52
32
|
* whitespace (spaces, tabs, newlines) so the resulting markup stays clean.
|
|
53
33
|
* @param context The rule context.
|
|
54
34
|
* @param prop The JSX attribute.
|
|
55
35
|
*/
|
|
56
|
-
function getPropRemovalRange(context, prop) {
|
|
36
|
+
function getPropRemovalRange$1(context, prop) {
|
|
57
37
|
const { sourceCode } = context;
|
|
58
38
|
let start = prop.range[0];
|
|
59
39
|
const end = prop.range[1];
|
|
@@ -61,31 +41,6 @@ function getPropRemovalRange(context, prop) {
|
|
|
61
41
|
return [start, end];
|
|
62
42
|
}
|
|
63
43
|
/**
|
|
64
|
-
* Extract the text to use as JSX children content from a `children` prop.
|
|
65
|
-
*
|
|
66
|
-
* - `children="text"` -> `text` (raw string, no quotes)
|
|
67
|
-
* - `children={<div />}` -> `<div />` (JSX element, no braces)
|
|
68
|
-
* - `children={<>…</>}` -> `<>…</>` (JSX fragment, no braces)
|
|
69
|
-
* - `children={expression}` -> `{expression}` (wrapped in braces)
|
|
70
|
-
* - `children` -> `null` (boolean shorthand, cannot extract)
|
|
71
|
-
* @param context The rule context.
|
|
72
|
-
* @param prop The JSX attribute.
|
|
73
|
-
*/
|
|
74
|
-
function getChildrenPropText(context, prop) {
|
|
75
|
-
const { sourceCode } = context;
|
|
76
|
-
const { value } = prop;
|
|
77
|
-
if (value == null) return null;
|
|
78
|
-
if (value.type === AST_NODE_TYPES.Literal) return String(value.value);
|
|
79
|
-
if (value.type === AST_NODE_TYPES.JSXExpressionContainer) {
|
|
80
|
-
const { expression } = value;
|
|
81
|
-
if (expression.type === AST_NODE_TYPES.JSXEmptyExpression) return null;
|
|
82
|
-
const exprText = sourceCode.getText(expression);
|
|
83
|
-
if (ast.isJSXElementLike(expression)) return exprText;
|
|
84
|
-
return `{${exprText}}`;
|
|
85
|
-
}
|
|
86
|
-
return null;
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
44
|
* Compute the range covering **all** children content of a JSX element or
|
|
90
45
|
* fragment (from the start of the first child to the end of the last child).
|
|
91
46
|
*
|
|
@@ -98,22 +53,13 @@ function getChildrenContentRange(node) {
|
|
|
98
53
|
const last = node.children[node.children.length - 1];
|
|
99
54
|
return [first.range[0], last.range[1]];
|
|
100
55
|
}
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
* @param context The rule context.
|
|
107
|
-
* @param node The JSX element or fragment.
|
|
108
|
-
*/
|
|
109
|
-
function getChildrenSourceText(context, node) {
|
|
110
|
-
const { sourceCode } = context;
|
|
111
|
-
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
112
|
-
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
113
|
-
if (opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing) return "";
|
|
114
|
-
if (closer == null) return "";
|
|
115
|
-
return sourceCode.text.slice(opener.range[1], closer.range[0]);
|
|
56
|
+
|
|
57
|
+
//#endregion
|
|
58
|
+
//#region src/utils/create-rule.ts
|
|
59
|
+
function getDocsUrl(ruleName) {
|
|
60
|
+
return `https://eslint-react.xyz/docs/rules/${ruleName}`;
|
|
116
61
|
}
|
|
62
|
+
const createRule = ESLintUtils.RuleCreator(getDocsUrl);
|
|
117
63
|
|
|
118
64
|
//#endregion
|
|
119
65
|
//#region src/rules/no-children-prop-with-children/no-children-prop-with-children.ts
|
|
@@ -152,7 +98,7 @@ function create$7(context) {
|
|
|
152
98
|
node: childrenProp,
|
|
153
99
|
suggest: [{
|
|
154
100
|
fix(fixer) {
|
|
155
|
-
const [start, end] = getPropRemovalRange(context, childrenProp);
|
|
101
|
+
const [start, end] = getPropRemovalRange$1(context, childrenProp);
|
|
156
102
|
return fixer.removeRange([start, end]);
|
|
157
103
|
},
|
|
158
104
|
messageId: "removeChildrenProp"
|
|
@@ -168,6 +114,47 @@ function create$7(context) {
|
|
|
168
114
|
} });
|
|
169
115
|
}
|
|
170
116
|
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/rules/no-children-prop/lib.ts
|
|
119
|
+
/**
|
|
120
|
+
* Compute the removal range for a JSX attribute, consuming any leading
|
|
121
|
+
* whitespace (spaces, tabs, newlines) so the resulting markup stays clean.
|
|
122
|
+
* @param context The rule context.
|
|
123
|
+
* @param prop The JSX attribute.
|
|
124
|
+
*/
|
|
125
|
+
function getPropRemovalRange(context, prop) {
|
|
126
|
+
const { sourceCode } = context;
|
|
127
|
+
let start = prop.range[0];
|
|
128
|
+
const end = prop.range[1];
|
|
129
|
+
while (start > 0 && /\s/.test(sourceCode.text[start - 1])) start--;
|
|
130
|
+
return [start, end];
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Extract the text to use as JSX children content from a `children` prop.
|
|
134
|
+
*
|
|
135
|
+
* - `children="text"` -> `text` (raw string, no quotes)
|
|
136
|
+
* - `children={<div />}` -> `<div />` (JSX element, no braces)
|
|
137
|
+
* - `children={<>…</>}` -> `<>…</>` (JSX fragment, no braces)
|
|
138
|
+
* - `children={expression}` -> `{expression}` (wrapped in braces)
|
|
139
|
+
* - `children` -> `null` (boolean shorthand, cannot extract)
|
|
140
|
+
* @param context The rule context.
|
|
141
|
+
* @param prop The JSX attribute.
|
|
142
|
+
*/
|
|
143
|
+
function getChildrenPropText(context, prop) {
|
|
144
|
+
const { sourceCode } = context;
|
|
145
|
+
const { value } = prop;
|
|
146
|
+
if (value == null) return null;
|
|
147
|
+
if (value.type === AST_NODE_TYPES.Literal) return String(value.value);
|
|
148
|
+
if (value.type === AST_NODE_TYPES.JSXExpressionContainer) {
|
|
149
|
+
const { expression } = value;
|
|
150
|
+
if (expression.type === AST_NODE_TYPES.JSXEmptyExpression) return null;
|
|
151
|
+
const exprText = sourceCode.getText(expression);
|
|
152
|
+
if (ast.isJSXElementLike(expression)) return exprText;
|
|
153
|
+
return `{${exprText}}`;
|
|
154
|
+
}
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
|
|
171
158
|
//#endregion
|
|
172
159
|
//#region src/rules/no-children-prop/no-children-prop.ts
|
|
173
160
|
const RULE_NAME$6 = "no-children-prop";
|
|
@@ -423,6 +410,38 @@ function create$1(context) {
|
|
|
423
410
|
} });
|
|
424
411
|
}
|
|
425
412
|
|
|
413
|
+
//#endregion
|
|
414
|
+
//#region src/rules/no-useless-fragment/lib.ts
|
|
415
|
+
/**
|
|
416
|
+
* Trim leading / trailing whitespace the same way React does when rendering
|
|
417
|
+
* JSX text. Whitespace that contains a newline is stripped entirely;
|
|
418
|
+
* whitespace that stays on the same line is preserved.
|
|
419
|
+
* @param text The JSX text to trim.
|
|
420
|
+
*/
|
|
421
|
+
function trimLikeReact(text) {
|
|
422
|
+
const leadingSpaces = /^\s*/.exec(text)?.[0] ?? "";
|
|
423
|
+
const trailingSpaces = /\s*$/.exec(text)?.[0] ?? "";
|
|
424
|
+
const start = leadingSpaces.includes("\n") ? leadingSpaces.length : 0;
|
|
425
|
+
const end = trailingSpaces.includes("\n") ? text.length - trailingSpaces.length : text.length;
|
|
426
|
+
return text.slice(start, end);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Extract the raw source text of an element's / fragment's children
|
|
430
|
+
* (everything between the opening and closing tags).
|
|
431
|
+
*
|
|
432
|
+
* Returns `""` for self-closing elements like `<Fragment />`.
|
|
433
|
+
* @param context The rule context.
|
|
434
|
+
* @param node The JSX element or fragment.
|
|
435
|
+
*/
|
|
436
|
+
function getChildrenSourceText(context, node) {
|
|
437
|
+
const { sourceCode } = context;
|
|
438
|
+
const opener = node.type === AST_NODE_TYPES.JSXFragment ? node.openingFragment : node.openingElement;
|
|
439
|
+
const closer = node.type === AST_NODE_TYPES.JSXFragment ? node.closingFragment : node.closingElement;
|
|
440
|
+
if (opener.type === AST_NODE_TYPES.JSXOpeningElement && opener.selfClosing) return "";
|
|
441
|
+
if (closer == null) return "";
|
|
442
|
+
return sourceCode.text.slice(opener.range[1], closer.range[0]);
|
|
443
|
+
}
|
|
444
|
+
|
|
426
445
|
//#endregion
|
|
427
446
|
//#region src/rules/no-useless-fragment/no-useless-fragment.ts
|
|
428
447
|
const RULE_NAME = "no-useless-fragment";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "eslint-plugin-react-jsx",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.2-next.0",
|
|
4
4
|
"description": "ESLint React's ESLint plugin for React Flavored JSX rules.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react",
|
|
@@ -43,11 +43,11 @@
|
|
|
43
43
|
"@typescript-eslint/utils": "^8.58.0",
|
|
44
44
|
"compare-versions": "^6.1.1",
|
|
45
45
|
"ts-pattern": "^5.9.0",
|
|
46
|
-
"@eslint-react/ast": "5.0.
|
|
47
|
-
"@eslint-react/core": "5.0.
|
|
48
|
-
"@eslint-react/
|
|
49
|
-
"@eslint-react/
|
|
50
|
-
"@eslint-react/
|
|
46
|
+
"@eslint-react/ast": "5.0.2-next.0",
|
|
47
|
+
"@eslint-react/core": "5.0.2-next.0",
|
|
48
|
+
"@eslint-react/shared": "5.0.2-next.0",
|
|
49
|
+
"@eslint-react/var": "5.0.2-next.0",
|
|
50
|
+
"@eslint-react/jsx": "5.0.2-next.0"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/react": "^19.2.14",
|