eslint-plugin-react-jsx 5.30.0-beta.4 → 5.30.0-beta.6

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 +60 -66
  2. package/package.json +8 -8
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
3
  import { getText } from "@eslint-react/eslint";
4
- import { collapseMultilineText, findAttribute, getChildren, getCreateElementChildrenArguments, getCreateElementProp, getElementFullType, hasAnyAttribute, hasChildren, isAttribute, isEmptyStringExpression, isFragmentElement, isHostElement, isWhitespaceText } from "@eslint-react/jsx";
5
- 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";
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.4";
22
+ var version = "5.30.0-beta.6";
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 prop = getCreateElementProp(context, node, "children");
54
- if (prop == null) return;
55
- if (getCreateElementChildrenArguments(context, node).length === 0) return;
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(context, node, "children");
63
- if (prop == null || !hasChildren(node)) return;
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 prop = getCreateElementProp(context, node, "children");
111
- if (prop == null) return;
112
- if (getCreateElementChildrenArguments(context, node).length > 0) return;
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(context, node, "children");
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
- const or = dual(2, (a, b) => (data) => a(data) || b(data));
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(isAttribute("key"))) context.report({
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: visit,
353
- JSXFragment: visit
315
+ JSXElement(node) {
316
+ visitForLeakedDollar(context, node);
317
+ },
318
+ JSXFragment(node) {
319
+ visitForLeakedDollar(context, node);
320
+ }
354
321
  };
355
322
  }
356
- const isWhitespaceOrEmptyStringExpression = or(isWhitespaceText, isEmptyStringExpression);
357
- function isNonSubstantiveChild(child) {
358
- if (isWhitespaceOrEmptyStringExpression(child)) return true;
359
- return child.type === AST_NODE_TYPES.JSXExpressionContainer && child.expression.type === AST_NODE_TYPES.JSXEmptyExpression;
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 = getElementFullType(node);
405
- if (!name.includes(":")) return;
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: node.openingElement.name
401
+ node: name
410
402
  });
411
403
  } };
412
404
  }
@@ -451,7 +443,7 @@ function create(context, [option]) {
451
443
  return {
452
444
  JSXElement(node) {
453
445
  if (!isFragmentElement(node, jsxFragmentFactory)) return;
454
- if (hasAnyAttribute(context, node, ["key", "ref"])) return;
446
+ if (hasIdentityAttribute(node)) return;
455
447
  visitFragment(context, node, options);
456
448
  },
457
449
  JSXFragment(node) {
@@ -459,6 +451,9 @@ function create(context, [option]) {
459
451
  }
460
452
  };
461
453
  }
454
+ function hasIdentityAttribute(node) {
455
+ return node.openingElement.attributes.some((a) => a.type === AST_NODE_TYPES.JSXSpreadAttribute) || hasAnyAttribute(node, ["key", "ref"]);
456
+ }
462
457
  function visitFragment(context, node, options) {
463
458
  const reasons = [];
464
459
  if (isHostElement(node.parent)) reasons.push("placed inside a host component");
@@ -484,7 +479,6 @@ function isContentUseless(node, options) {
484
479
  return true;
485
480
  }
486
481
  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
482
  if (Check.isJSXElementOrFragment(node.parent)) return isHostElement(node.parent);
489
483
  if (!node.children.some((child) => Check.isJSXElementOrFragment(child))) return false;
490
484
  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.4",
3
+ "version": "5.30.0-beta.6",
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.4",
41
- "@eslint-react/core": "5.30.0-beta.4",
42
- "@eslint-react/eslint": "5.30.0-beta.4",
43
- "@eslint-react/jsx": "5.30.0-beta.4",
44
- "@eslint-react/shared": "5.30.0-beta.4",
45
- "@typescript-eslint/types": "^8.72.0",
46
- "@typescript-eslint/utils": "^8.72.0"
40
+ "@eslint-react/ast": "5.30.0-beta.6",
41
+ "@eslint-react/core": "5.30.0-beta.6",
42
+ "@eslint-react/eslint": "5.30.0-beta.6",
43
+ "@eslint-react/jsx": "5.30.0-beta.6",
44
+ "@eslint-react/shared": "5.30.0-beta.6",
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",