eslint-plugin-react-jsx 5.7.10 → 5.8.1

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.
Files changed (2) hide show
  1. package/dist/index.js +116 -61
  2. package/package.json +6 -6
package/dist/index.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import { DEFAULT_ESLINT_REACT_SETTINGS } from "@eslint-react/shared";
2
2
  import { ESLintUtils } from "@typescript-eslint/utils";
3
+ import * as core from "@eslint-react/core";
3
4
  import { merge } from "@eslint-react/eslint";
4
5
  import { findAttribute, getChildren, getElementFullType, hasAnyAttribute, hasChildren, isFragmentElement, isHostElement, isWhitespaceText } from "@eslint-react/jsx";
5
6
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
6
- import { Check, isOneOf } from "@eslint-react/ast";
7
- import * as core from "@eslint-react/core";
7
+ import { Check, Extract, isOneOf } from "@eslint-react/ast";
8
8
  import ts from "typescript";
9
9
 
10
10
  //#region \0rolldown/runtime.js
@@ -26,7 +26,7 @@ var __exportAll = (all, no_symbols) => {
26
26
  //#endregion
27
27
  //#region package.json
28
28
  var name$2 = "eslint-plugin-react-jsx";
29
- var version = "5.7.10";
29
+ var version = "5.8.1";
30
30
 
31
31
  //#endregion
32
32
  //#region src/utils/create-rule.ts
@@ -38,6 +38,20 @@ const createRule = ESLintUtils.RuleCreator(getDocsUrl);
38
38
  //#endregion
39
39
  //#region src/rules/no-children-prop-with-children/lib.ts
40
40
  /**
41
+ * Find a `children` property inside an ObjectExpression.
42
+ * @param node The object expression.
43
+ * @returns The Property node whose key is "children", or null.
44
+ */
45
+ function findChildrenProperty$1(node) {
46
+ for (const prop of node.properties) {
47
+ if (prop.type !== AST_NODE_TYPES.Property) continue;
48
+ const key = Extract.unwrap(prop.key);
49
+ if (key.type === AST_NODE_TYPES.Identifier && key.name === "children") return prop;
50
+ if (key.type === AST_NODE_TYPES.Literal && key.value === "children") return prop;
51
+ }
52
+ return null;
53
+ }
54
+ /**
41
55
  * Compute the removal range for a JSX attribute, consuming any leading
42
56
  * whitespace (spaces, tabs, newlines) so the resulting markup stays clean.
43
57
  * @param context The rule context.
@@ -85,41 +99,69 @@ var no_children_prop_with_children_default = createRule({
85
99
  defaultOptions: []
86
100
  });
87
101
  function create$7(context) {
88
- return merge({ JSXElement(node) {
89
- const childrenProp = findAttribute(context, node, "children");
90
- if (childrenProp == null) return;
91
- if (!hasChildren(node)) return;
92
- if (childrenProp.type !== AST_NODE_TYPES.JSXAttribute) {
102
+ return merge({
103
+ CallExpression(node) {
104
+ if (!core.isCreateElementCall(context, node)) return;
105
+ const [, propsArg, firstExtra] = node.arguments;
106
+ if (propsArg == null || propsArg.type !== AST_NODE_TYPES.ObjectExpression) return;
107
+ const childrenProp = findChildrenProperty$1(propsArg);
108
+ if (childrenProp == null) return;
109
+ if (firstExtra == null) return;
93
110
  context.report({
94
111
  messageId: "default",
95
112
  node: childrenProp
96
113
  });
97
- return;
114
+ },
115
+ JSXElement(node) {
116
+ const childrenProp = findAttribute(context, node, "children");
117
+ if (childrenProp == null) return;
118
+ if (!hasChildren(node)) return;
119
+ if (childrenProp.type !== AST_NODE_TYPES.JSXAttribute) {
120
+ context.report({
121
+ messageId: "default",
122
+ node: childrenProp
123
+ });
124
+ return;
125
+ }
126
+ context.report({
127
+ messageId: "default",
128
+ node: childrenProp,
129
+ suggest: [{
130
+ fix(fixer) {
131
+ const [start, end] = getPropRemovalRange$1(context, childrenProp);
132
+ return fixer.removeRange([start, end]);
133
+ },
134
+ messageId: "removeChildrenProp"
135
+ }, {
136
+ fix(fixer) {
137
+ const range = getChildrenContentRange(node);
138
+ if (range == null) return [];
139
+ return fixer.removeRange(range);
140
+ },
141
+ messageId: "removeChildrenContent"
142
+ }]
143
+ });
98
144
  }
99
- context.report({
100
- messageId: "default",
101
- node: childrenProp,
102
- suggest: [{
103
- fix(fixer) {
104
- const [start, end] = getPropRemovalRange$1(context, childrenProp);
105
- return fixer.removeRange([start, end]);
106
- },
107
- messageId: "removeChildrenProp"
108
- }, {
109
- fix(fixer) {
110
- const range = getChildrenContentRange(node);
111
- if (range == null) return [];
112
- return fixer.removeRange(range);
113
- },
114
- messageId: "removeChildrenContent"
115
- }]
116
- });
117
- } });
145
+ });
118
146
  }
119
147
 
120
148
  //#endregion
121
149
  //#region src/rules/no-children-prop/lib.ts
122
150
  /**
151
+ * Find a `children` property inside an ObjectExpression.
152
+ * @param node The object expression.
153
+ * @returns The Property node whose key is "children", or null.
154
+ */
155
+ function findChildrenProperty(node) {
156
+ for (const prop of node.properties) {
157
+ if (prop.type !== AST_NODE_TYPES.Property) continue;
158
+ const key = Extract.unwrap(prop.key);
159
+ if (key.type === AST_NODE_TYPES.Identifier && key.name === "children") return prop;
160
+ if (key.type === AST_NODE_TYPES.Literal && key.value === "children") return prop;
161
+ }
162
+ return null;
163
+ }
164
+ /**
123
165
  * Compute the removal range for a JSX attribute, consuming any leading
124
166
  * whitespace (spaces, tabs, newlines) so the resulting markup stays clean.
125
167
  * @param context The rule context.
@@ -178,47 +220,60 @@ var no_children_prop_default = createRule({
178
220
  defaultOptions: []
179
221
  });
180
222
  function create$6(context) {
181
- return merge({ JSXElement(node) {
182
- const childrenProp = findAttribute(context, node, "children");
183
- if (childrenProp == null) return;
184
- if (childrenProp.type !== AST_NODE_TYPES.JSXAttribute) {
223
+ return merge({
224
+ JSXElement(node) {
225
+ const childrenProp = findAttribute(context, node, "children");
226
+ if (childrenProp == null) return;
227
+ if (childrenProp.type !== AST_NODE_TYPES.JSXAttribute) {
228
+ context.report({
229
+ messageId: "default",
230
+ node: childrenProp
231
+ });
232
+ return;
233
+ }
234
+ const childrenText = getChildrenPropText(context, childrenProp);
235
+ if (childrenText == null) {
236
+ context.report({
237
+ messageId: "default",
238
+ node: childrenProp
239
+ });
240
+ return;
241
+ }
185
242
  context.report({
186
243
  messageId: "default",
187
- node: childrenProp
244
+ node: childrenProp,
245
+ suggest: [{
246
+ fix(fixer) {
247
+ const sourceCode = context.sourceCode;
248
+ const { openingElement } = node;
249
+ const [removeStart, removeEnd] = getPropRemovalRange(context, childrenProp);
250
+ if (openingElement.selfClosing) {
251
+ const tagName = sourceCode.getText(openingElement.name);
252
+ const selfCloseOffset = sourceCode.getText(openingElement).lastIndexOf("/>");
253
+ let wsStart = openingElement.range[0] + selfCloseOffset;
254
+ while (wsStart > removeEnd && /\s/.test(sourceCode.text[wsStart - 1])) wsStart--;
255
+ return [fixer.removeRange([removeStart, removeEnd]), fixer.replaceTextRange([wsStart, openingElement.range[1]], `>${childrenText}</${tagName}>`)];
256
+ }
257
+ const fixes = [fixer.removeRange([removeStart, removeEnd])];
258
+ if (node.closingElement != null) fixes.push(fixer.insertTextBefore(node.closingElement, childrenText));
259
+ return fixes;
260
+ },
261
+ messageId: "moveChildrenToContent"
262
+ }]
188
263
  });
189
- return;
190
- }
191
- const childrenText = getChildrenPropText(context, childrenProp);
192
- if (childrenText == null) {
264
+ },
265
+ CallExpression(node) {
266
+ if (!core.isCreateElementCall(context, node)) return;
267
+ const [, propsArg] = node.arguments;
268
+ if (propsArg == null || propsArg.type !== AST_NODE_TYPES.ObjectExpression) return;
269
+ const childrenProp = findChildrenProperty(propsArg);
270
+ if (childrenProp == null) return;
193
271
  context.report({
194
272
  messageId: "default",
195
273
  node: childrenProp
196
274
  });
197
- return;
198
275
  }
199
- context.report({
200
- messageId: "default",
201
- node: childrenProp,
202
- suggest: [{
203
- fix(fixer) {
204
- const sourceCode = context.sourceCode;
205
- const { openingElement } = node;
206
- const [removeStart, removeEnd] = getPropRemovalRange(context, childrenProp);
207
- if (openingElement.selfClosing) {
208
- const tagName = sourceCode.getText(openingElement.name);
209
- const selfCloseOffset = sourceCode.getText(openingElement).lastIndexOf("/>");
210
- let wsStart = openingElement.range[0] + selfCloseOffset;
211
- while (wsStart > removeEnd && /\s/.test(sourceCode.text[wsStart - 1])) wsStart--;
212
- return [fixer.removeRange([removeStart, removeEnd]), fixer.replaceTextRange([wsStart, openingElement.range[1]], `>${childrenText}</${tagName}>`)];
213
- }
214
- const fixes = [fixer.removeRange([removeStart, removeEnd])];
215
- if (node.closingElement != null) fixes.push(fixer.insertTextBefore(node.closingElement, childrenText));
216
- return fixes;
217
- },
218
- messageId: "moveChildrenToContent"
219
- }]
220
- });
221
- } });
276
+ });
222
277
  }
223
278
 
224
279
  //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-jsx",
3
- "version": "5.7.10",
3
+ "version": "5.8.1",
4
4
  "description": "ESLint React's ESLint plugin for React Flavored JSX rules.",
5
5
  "keywords": [
6
6
  "react",
@@ -39,11 +39,11 @@
39
39
  "dependencies": {
40
40
  "@typescript-eslint/types": "^8.59.3",
41
41
  "@typescript-eslint/utils": "^8.59.3",
42
- "@eslint-react/ast": "5.7.10",
43
- "@eslint-react/core": "5.7.10",
44
- "@eslint-react/eslint": "5.7.10",
45
- "@eslint-react/shared": "5.7.10",
46
- "@eslint-react/jsx": "5.7.10"
42
+ "@eslint-react/ast": "5.8.1",
43
+ "@eslint-react/core": "5.8.1",
44
+ "@eslint-react/eslint": "5.8.1",
45
+ "@eslint-react/jsx": "5.8.1",
46
+ "@eslint-react/shared": "5.8.1"
47
47
  },
48
48
  "devDependencies": {
49
49
  "@types/react": "^19.2.14",