eslint-plugin-react-x 1.42.2-beta.5 → 1.42.2-next.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.
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # eslint-plugin-react-x
2
2
 
3
- A series of future-proof ESLint rules for React and friends.
3
+ A series of composable ESLint rules for React and friends.
4
4
 
5
5
  ## Install
6
6
 
package/dist/index.js CHANGED
@@ -4,13 +4,13 @@ var shared = require('@eslint-react/shared');
4
4
  var JSX8 = require('@eslint-react/jsx');
5
5
  var utils = require('@typescript-eslint/utils');
6
6
  var types = require('@typescript-eslint/types');
7
+ var eff = require('@eslint-react/eff');
7
8
  var VAR2 = require('@eslint-react/var');
8
9
  var tsPattern = require('ts-pattern');
9
10
  var kit = require('@eslint-react/kit');
10
11
  var ts = require('typescript');
11
12
  var AST8 = require('@eslint-react/ast');
12
13
  var ER21 = require('@eslint-react/core');
13
- var eff = require('@eslint-react/eff');
14
14
  var compareVersions = require('compare-versions');
15
15
  var typeUtils = require('@typescript-eslint/type-utils');
16
16
  var tsApiUtils = require('ts-api-utils');
@@ -141,7 +141,7 @@ var settings3 = {
141
141
 
142
142
  // package.json
143
143
  var name4 = "eslint-plugin-react-x";
144
- var version = "1.42.2-beta.5";
144
+ var version = "1.42.2-next.1";
145
145
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
146
146
 
147
147
  // src/rules/avoid-shorthand-boolean.ts
@@ -167,7 +167,7 @@ var avoid_shorthand_boolean_default = createRule({
167
167
  function create(context) {
168
168
  return {
169
169
  JSXAttribute(node) {
170
- if (node.value == null) {
170
+ if (node.value === null) {
171
171
  context.report({
172
172
  messageId: "avoidShorthandBoolean",
173
173
  node,
@@ -273,7 +273,7 @@ var jsx_no_undef_default = createRule({
273
273
  function create4(context) {
274
274
  return {
275
275
  JSXOpeningElement(node) {
276
- const name5 = tsPattern.match(node.name).with({ type: types.AST_NODE_TYPES.JSXIdentifier }, (n) => n.name).with({ type: types.AST_NODE_TYPES.JSXMemberExpression, object: { type: types.AST_NODE_TYPES.JSXIdentifier } }, (n) => n.object.name).otherwise(() => null);
276
+ const name5 = tsPattern.match(node.name).with({ type: types.AST_NODE_TYPES.JSXIdentifier }, (n) => n.name).with({ type: types.AST_NODE_TYPES.JSXMemberExpression, object: { type: types.AST_NODE_TYPES.JSXIdentifier } }, (n) => n.object.name).otherwise(() => eff._);
277
277
  if (name5 == null) return;
278
278
  if (name5 === "this") return;
279
279
  if (/^[a-z]/u.test(name5)) return;
@@ -645,9 +645,7 @@ function create8(context) {
645
645
  if (!("value" in prop)) {
646
646
  continue;
647
647
  }
648
- for (const descriptor of getReportDescriptors(prop.value)) {
649
- report(descriptor);
650
- }
648
+ getReportDescriptors(prop.value).forEach(report);
651
649
  }
652
650
  },
653
651
  "CallExpression:exit"() {
@@ -663,9 +661,7 @@ function create8(context) {
663
661
  if (node.value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
664
662
  return;
665
663
  }
666
- for (const descriptor of getReportDescriptors(node.value.expression)) {
667
- report(descriptor);
668
- }
664
+ getReportDescriptors(node.value.expression).forEach(report);
669
665
  }
670
666
  };
671
667
  }
@@ -810,12 +806,15 @@ var no_children_prop_default = createRule({
810
806
  function create13(context) {
811
807
  return {
812
808
  JSXElement(node) {
813
- const attributes = node.openingElement.attributes;
814
- const childrenProp = JSX8__namespace.getAttribute("children", attributes, context.sourceCode.getScope(node));
815
- if (childrenProp != null) {
809
+ const attribute = JSX8__namespace.getAttribute(
810
+ "children",
811
+ node.openingElement.attributes,
812
+ context.sourceCode.getScope(node)
813
+ );
814
+ if (attribute != null) {
816
815
  context.report({
817
816
  messageId: "noChildrenProp",
818
- node: childrenProp
817
+ node: attribute
819
818
  });
820
819
  }
821
820
  }
@@ -912,12 +911,13 @@ var no_clone_element_default = createRule({
912
911
  function create16(context) {
913
912
  return {
914
913
  CallExpression(node) {
915
- if (ER21__namespace.isCloneElementCall(context, node)) {
916
- context.report({
917
- messageId: "noCloneElement",
918
- node
919
- });
914
+ if (!ER21__namespace.isCloneElementCall(context, node)) {
915
+ return;
920
916
  }
917
+ context.report({
918
+ messageId: "noCloneElement",
919
+ node
920
+ });
921
921
  }
922
922
  };
923
923
  }
@@ -1481,8 +1481,8 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
1481
1481
  if (arg0 == null) {
1482
1482
  return [];
1483
1483
  }
1484
- const fixedArg0Text = tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: types.AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => null);
1485
- const fixedArg1Text = tsPattern.match(arg1).with(tsPattern.P.nullish, () => "ref").with({ type: types.AST_NODE_TYPES.Identifier, name: "ref" }, () => "ref").with({ type: types.AST_NODE_TYPES.Identifier, name: tsPattern.P.string }, (n) => `ref: ${n.name}`).otherwise(() => null);
1484
+ const fixedArg0Text = tsPattern.match(arg0).with({ type: types.AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: types.AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => eff._);
1485
+ const fixedArg1Text = tsPattern.match(arg1).with(tsPattern.P.nullish, () => "ref").with({ type: types.AST_NODE_TYPES.Identifier, name: "ref" }, () => "ref").with({ type: types.AST_NODE_TYPES.Identifier, name: tsPattern.P.string }, (n) => `ref: ${n.name}`).otherwise(() => eff._);
1486
1486
  if (fixedArg0Text == null || fixedArg1Text == null) {
1487
1487
  return [];
1488
1488
  }
@@ -1912,15 +1912,22 @@ function create32(context) {
1912
1912
  },
1913
1913
  CallExpression(node) {
1914
1914
  state.isWithinChildrenToArray ||= ER21__namespace.isChildrenToArrayCall(context, node);
1915
- if (state.isWithinChildrenToArray) return;
1916
- const callback = tsPattern.match(node).when(AST8__namespace.isArrayMapCall, (n) => n.arguments[0]).when(AST8__namespace.isArrayFromCall, (n) => n.arguments[1]).otherwise(() => null);
1917
- if (!AST8__namespace.isFunction(callback)) return;
1918
- const body = callback.body;
1919
- if (body.type === types.AST_NODE_TYPES.BlockStatement) {
1920
- checkBlockStatement(body).forEach(report);
1915
+ if (state.isWithinChildrenToArray) {
1916
+ return;
1917
+ }
1918
+ const isMapCall = AST8__namespace.isArrayMapCall(node);
1919
+ if (!isMapCall && !AST8__namespace.isArrayFromCall(node)) {
1920
+ return;
1921
+ }
1922
+ const fn = node.arguments[isMapCall ? 0 : 1];
1923
+ if (!AST8__namespace.isFunction(fn)) {
1924
+ return;
1925
+ }
1926
+ if (fn.body.type === types.AST_NODE_TYPES.BlockStatement) {
1927
+ checkBlockStatement(fn.body).forEach(report);
1921
1928
  return;
1922
1929
  }
1923
- report(checkExpression(body));
1930
+ report(checkExpression(fn.body));
1924
1931
  },
1925
1932
  "CallExpression:exit"(node) {
1926
1933
  if (!ER21__namespace.isChildrenToArrayCall(context, node)) {
package/dist/index.mjs CHANGED
@@ -2,13 +2,13 @@ import { getDocsUrl, getSettingsFromContext, unsafeDecodeSettings, DEFAULT_ESLIN
2
2
  import * as JSX8 from '@eslint-react/jsx';
3
3
  import { ESLintUtils } from '@typescript-eslint/utils';
4
4
  import { AST_NODE_TYPES } from '@typescript-eslint/types';
5
+ import { _, flow, getOrUpdate, constTrue, constFalse } from '@eslint-react/eff';
5
6
  import * as VAR2 from '@eslint-react/var';
6
7
  import { match, isMatching, P } from 'ts-pattern';
7
8
  import { JsxConfig, createReport } from '@eslint-react/kit';
8
9
  import ts, { JsxEmit } from 'typescript';
9
10
  import * as AST8 from '@eslint-react/ast';
10
11
  import * as ER21 from '@eslint-react/core';
11
- import { flow, getOrUpdate, constTrue, constFalse, _ } from '@eslint-react/eff';
12
12
  import { compare } from 'compare-versions';
13
13
  import { getConstrainedTypeAtLocation, isTypeReadonly } from '@typescript-eslint/type-utils';
14
14
  import { unionTypeParts, isTypeFlagSet, isTrueLiteralType, isFalseLiteralType } from 'ts-api-utils';
@@ -113,7 +113,7 @@ var settings3 = {
113
113
 
114
114
  // package.json
115
115
  var name4 = "eslint-plugin-react-x";
116
- var version = "1.42.2-beta.5";
116
+ var version = "1.42.2-next.1";
117
117
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
118
118
 
119
119
  // src/rules/avoid-shorthand-boolean.ts
@@ -139,7 +139,7 @@ var avoid_shorthand_boolean_default = createRule({
139
139
  function create(context) {
140
140
  return {
141
141
  JSXAttribute(node) {
142
- if (node.value == null) {
142
+ if (node.value === null) {
143
143
  context.report({
144
144
  messageId: "avoidShorthandBoolean",
145
145
  node,
@@ -245,7 +245,7 @@ var jsx_no_undef_default = createRule({
245
245
  function create4(context) {
246
246
  return {
247
247
  JSXOpeningElement(node) {
248
- const name5 = match(node.name).with({ type: AST_NODE_TYPES.JSXIdentifier }, (n) => n.name).with({ type: AST_NODE_TYPES.JSXMemberExpression, object: { type: AST_NODE_TYPES.JSXIdentifier } }, (n) => n.object.name).otherwise(() => null);
248
+ const name5 = match(node.name).with({ type: AST_NODE_TYPES.JSXIdentifier }, (n) => n.name).with({ type: AST_NODE_TYPES.JSXMemberExpression, object: { type: AST_NODE_TYPES.JSXIdentifier } }, (n) => n.object.name).otherwise(() => _);
249
249
  if (name5 == null) return;
250
250
  if (name5 === "this") return;
251
251
  if (/^[a-z]/u.test(name5)) return;
@@ -617,9 +617,7 @@ function create8(context) {
617
617
  if (!("value" in prop)) {
618
618
  continue;
619
619
  }
620
- for (const descriptor of getReportDescriptors(prop.value)) {
621
- report(descriptor);
622
- }
620
+ getReportDescriptors(prop.value).forEach(report);
623
621
  }
624
622
  },
625
623
  "CallExpression:exit"() {
@@ -635,9 +633,7 @@ function create8(context) {
635
633
  if (node.value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
636
634
  return;
637
635
  }
638
- for (const descriptor of getReportDescriptors(node.value.expression)) {
639
- report(descriptor);
640
- }
636
+ getReportDescriptors(node.value.expression).forEach(report);
641
637
  }
642
638
  };
643
639
  }
@@ -782,12 +778,15 @@ var no_children_prop_default = createRule({
782
778
  function create13(context) {
783
779
  return {
784
780
  JSXElement(node) {
785
- const attributes = node.openingElement.attributes;
786
- const childrenProp = JSX8.getAttribute("children", attributes, context.sourceCode.getScope(node));
787
- if (childrenProp != null) {
781
+ const attribute = JSX8.getAttribute(
782
+ "children",
783
+ node.openingElement.attributes,
784
+ context.sourceCode.getScope(node)
785
+ );
786
+ if (attribute != null) {
788
787
  context.report({
789
788
  messageId: "noChildrenProp",
790
- node: childrenProp
789
+ node: attribute
791
790
  });
792
791
  }
793
792
  }
@@ -884,12 +883,13 @@ var no_clone_element_default = createRule({
884
883
  function create16(context) {
885
884
  return {
886
885
  CallExpression(node) {
887
- if (ER21.isCloneElementCall(context, node)) {
888
- context.report({
889
- messageId: "noCloneElement",
890
- node
891
- });
886
+ if (!ER21.isCloneElementCall(context, node)) {
887
+ return;
892
888
  }
889
+ context.report({
890
+ messageId: "noCloneElement",
891
+ node
892
+ });
893
893
  }
894
894
  };
895
895
  }
@@ -1453,8 +1453,8 @@ function getComponentPropsFixes(context, fixer, node, typeArguments) {
1453
1453
  if (arg0 == null) {
1454
1454
  return [];
1455
1455
  }
1456
- const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => null);
1457
- const fixedArg1Text = match(arg1).with(P.nullish, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: "ref" }, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: P.string }, (n) => `ref: ${n.name}`).otherwise(() => null);
1456
+ const fixedArg0Text = match(arg0).with({ type: AST_NODE_TYPES.Identifier }, (n) => `...${n.name}`).with({ type: AST_NODE_TYPES.ObjectPattern }, (n) => n.properties.map(getText).join(", ")).otherwise(() => _);
1457
+ const fixedArg1Text = match(arg1).with(P.nullish, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: "ref" }, () => "ref").with({ type: AST_NODE_TYPES.Identifier, name: P.string }, (n) => `ref: ${n.name}`).otherwise(() => _);
1458
1458
  if (fixedArg0Text == null || fixedArg1Text == null) {
1459
1459
  return [];
1460
1460
  }
@@ -1884,15 +1884,22 @@ function create32(context) {
1884
1884
  },
1885
1885
  CallExpression(node) {
1886
1886
  state.isWithinChildrenToArray ||= ER21.isChildrenToArrayCall(context, node);
1887
- if (state.isWithinChildrenToArray) return;
1888
- const callback = match(node).when(AST8.isArrayMapCall, (n) => n.arguments[0]).when(AST8.isArrayFromCall, (n) => n.arguments[1]).otherwise(() => null);
1889
- if (!AST8.isFunction(callback)) return;
1890
- const body = callback.body;
1891
- if (body.type === AST_NODE_TYPES.BlockStatement) {
1892
- checkBlockStatement(body).forEach(report);
1887
+ if (state.isWithinChildrenToArray) {
1888
+ return;
1889
+ }
1890
+ const isMapCall = AST8.isArrayMapCall(node);
1891
+ if (!isMapCall && !AST8.isArrayFromCall(node)) {
1892
+ return;
1893
+ }
1894
+ const fn = node.arguments[isMapCall ? 0 : 1];
1895
+ if (!AST8.isFunction(fn)) {
1896
+ return;
1897
+ }
1898
+ if (fn.body.type === AST_NODE_TYPES.BlockStatement) {
1899
+ checkBlockStatement(fn.body).forEach(report);
1893
1900
  return;
1894
1901
  }
1895
- report(checkExpression(body));
1902
+ report(checkExpression(fn.body));
1896
1903
  },
1897
1904
  "CallExpression:exit"(node) {
1898
1905
  if (!ER21.isChildrenToArrayCall(context, node)) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.42.2-beta.5",
4
- "description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
3
+ "version": "1.42.2-next.1",
4
+ "description": "A series of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
5
5
  "keywords": [
6
6
  "react",
7
7
  "eslint",
@@ -50,17 +50,17 @@
50
50
  "is-immutable-type": "^5.0.1",
51
51
  "string-ts": "^2.2.1",
52
52
  "ts-pattern": "^5.7.0",
53
- "@eslint-react/ast": "1.42.2-beta.5",
54
- "@eslint-react/jsx": "1.42.2-beta.5",
55
- "@eslint-react/core": "1.42.2-beta.5",
56
- "@eslint-react/kit": "1.42.2-beta.5",
57
- "@eslint-react/eff": "1.42.2-beta.5",
58
- "@eslint-react/shared": "1.42.2-beta.5",
59
- "@eslint-react/var": "1.42.2-beta.5"
53
+ "@eslint-react/core": "1.42.2-next.1",
54
+ "@eslint-react/ast": "1.42.2-next.1",
55
+ "@eslint-react/eff": "1.42.2-next.1",
56
+ "@eslint-react/jsx": "1.42.2-next.1",
57
+ "@eslint-react/kit": "1.42.2-next.1",
58
+ "@eslint-react/shared": "1.42.2-next.1",
59
+ "@eslint-react/var": "1.42.2-next.1"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/react": "^19.1.0",
63
- "@types/react-dom": "^19.1.2",
63
+ "@types/react-dom": "^19.1.1",
64
64
  "ts-api-utils": "^2.1.0",
65
65
  "tsup": "^8.4.0",
66
66
  "@local/configs": "0.0.0"