eslint-plugin-react-x 1.42.2-next.5 → 1.43.0-beta.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 CHANGED
@@ -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-next.5";
144
+ var version = "1.43.0-beta.0";
145
145
  var createRule = utils.ESLintUtils.RuleCreator(shared.getDocsUrl("x"));
146
146
 
147
147
  // src/rules/avoid-shorthand-boolean.ts
@@ -1976,7 +1976,7 @@ function create33(context) {
1976
1976
  const isFunctionComponent = (node2) => {
1977
1977
  return AST8__namespace.isFunction(node2) && functionComponents.some((component) => component.node === node2);
1978
1978
  };
1979
- const isClassComponent11 = (node2) => {
1979
+ const isClassComponent12 = (node2) => {
1980
1980
  return AST8__namespace.isClass(node2) && classComponents.some((component) => component.node === node2);
1981
1981
  };
1982
1982
  for (const { name: name5, node: component } of functionComponents) {
@@ -2030,7 +2030,7 @@ function create33(context) {
2030
2030
  }
2031
2031
  }
2032
2032
  for (const { name: name5 = "unknown", node: component } of classComponents) {
2033
- if (AST8__namespace.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
2033
+ if (AST8__namespace.findParentNode(component, (n) => isClassComponent12(n) || isFunctionComponent(n)) == null) {
2034
2034
  continue;
2035
2035
  }
2036
2036
  context.report({
@@ -2275,26 +2275,17 @@ function create38(context) {
2275
2275
  };
2276
2276
  }
2277
2277
  var RULE_NAME39 = "no-string-refs";
2278
- var RULE_FEATURES39 = [];
2279
- function containsStringLiteral({ value }) {
2280
- return value?.type === types.AST_NODE_TYPES.Literal && typeof value.value === "string";
2281
- }
2282
- function containsStringExpressionContainer({ value }) {
2283
- if (value?.type !== types.AST_NODE_TYPES.JSXExpressionContainer) {
2284
- return false;
2285
- }
2286
- if (value.expression.type === types.AST_NODE_TYPES.Literal) {
2287
- return typeof value.expression.value === "string";
2288
- }
2289
- return value.expression.type === types.AST_NODE_TYPES.TemplateLiteral;
2290
- }
2278
+ var RULE_FEATURES39 = [
2279
+ "MOD"
2280
+ ];
2291
2281
  var no_string_refs_default = createRule({
2292
2282
  meta: {
2293
2283
  type: "problem",
2294
2284
  docs: {
2295
- description: "Disallow deprecated string `refs`.",
2285
+ description: "Replaces string refs with callback refs.",
2296
2286
  [Symbol.for("rule_features")]: RULE_FEATURES39
2297
2287
  },
2288
+ fixable: "code",
2298
2289
  messages: {
2299
2290
  noStringRefs: "[Deprecated] Use callback refs instead."
2300
2291
  },
@@ -2305,20 +2296,49 @@ var no_string_refs_default = createRule({
2305
2296
  defaultOptions: []
2306
2297
  });
2307
2298
  function create39(context) {
2299
+ const state = {
2300
+ isWithinClassComponent: false
2301
+ };
2302
+ function onClassBodyEnter(node) {
2303
+ if (ER21__namespace.isClassComponent(node.parent)) {
2304
+ state.isWithinClassComponent = true;
2305
+ }
2306
+ }
2307
+ function onClassBodyExit() {
2308
+ state.isWithinClassComponent = false;
2309
+ }
2308
2310
  return {
2311
+ ClassBody: onClassBodyEnter,
2312
+ "ClassBody:exit": onClassBodyExit,
2309
2313
  JSXAttribute(node) {
2310
- if (node.name.name !== "ref") {
2311
- return;
2312
- }
2313
- if (containsStringLiteral(node) || containsStringExpressionContainer(node)) {
2314
- context.report({
2315
- messageId: "noStringRefs",
2316
- node
2317
- });
2318
- }
2314
+ if (node.name.name !== "ref") return;
2315
+ const refNameText = getAttributeValueText(context, node.value);
2316
+ if (refNameText == null) return;
2317
+ context.report({
2318
+ messageId: "noStringRefs",
2319
+ node,
2320
+ fix(fixer) {
2321
+ if (node.value == null) return null;
2322
+ if (!state.isWithinClassComponent) return null;
2323
+ return fixer.replaceText(node.value, `{(ref) => { this.refs[${refNameText}] = ref; }}`);
2324
+ }
2325
+ });
2319
2326
  }
2320
2327
  };
2321
2328
  }
2329
+ function getAttributeValueText(context, node) {
2330
+ if (node == null) return null;
2331
+ switch (true) {
2332
+ case (node.type === types.AST_NODE_TYPES.Literal && typeof node.value === "string"):
2333
+ return context.sourceCode.getText(node);
2334
+ case (node.type === types.AST_NODE_TYPES.JSXExpressionContainer && node.expression.type === types.AST_NODE_TYPES.Literal && typeof node.expression.value === "string"):
2335
+ return context.sourceCode.getText(node.expression);
2336
+ case (node.type === types.AST_NODE_TYPES.JSXExpressionContainer && node.expression.type === types.AST_NODE_TYPES.TemplateLiteral):
2337
+ return context.sourceCode.getText(node.expression);
2338
+ default:
2339
+ return null;
2340
+ }
2341
+ }
2322
2342
  var RULE_NAME40 = "no-unsafe-component-will-mount";
2323
2343
  var RULE_FEATURES40 = [];
2324
2344
  function isUnsafeComponentWillMount(node) {
package/dist/index.mjs CHANGED
@@ -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-next.5";
116
+ var version = "1.43.0-beta.0";
117
117
  var createRule = ESLintUtils.RuleCreator(getDocsUrl("x"));
118
118
 
119
119
  // src/rules/avoid-shorthand-boolean.ts
@@ -1948,7 +1948,7 @@ function create33(context) {
1948
1948
  const isFunctionComponent = (node2) => {
1949
1949
  return AST8.isFunction(node2) && functionComponents.some((component) => component.node === node2);
1950
1950
  };
1951
- const isClassComponent11 = (node2) => {
1951
+ const isClassComponent12 = (node2) => {
1952
1952
  return AST8.isClass(node2) && classComponents.some((component) => component.node === node2);
1953
1953
  };
1954
1954
  for (const { name: name5, node: component } of functionComponents) {
@@ -2002,7 +2002,7 @@ function create33(context) {
2002
2002
  }
2003
2003
  }
2004
2004
  for (const { name: name5 = "unknown", node: component } of classComponents) {
2005
- if (AST8.findParentNode(component, (n) => isClassComponent11(n) || isFunctionComponent(n)) == null) {
2005
+ if (AST8.findParentNode(component, (n) => isClassComponent12(n) || isFunctionComponent(n)) == null) {
2006
2006
  continue;
2007
2007
  }
2008
2008
  context.report({
@@ -2247,26 +2247,17 @@ function create38(context) {
2247
2247
  };
2248
2248
  }
2249
2249
  var RULE_NAME39 = "no-string-refs";
2250
- var RULE_FEATURES39 = [];
2251
- function containsStringLiteral({ value }) {
2252
- return value?.type === AST_NODE_TYPES.Literal && typeof value.value === "string";
2253
- }
2254
- function containsStringExpressionContainer({ value }) {
2255
- if (value?.type !== AST_NODE_TYPES.JSXExpressionContainer) {
2256
- return false;
2257
- }
2258
- if (value.expression.type === AST_NODE_TYPES.Literal) {
2259
- return typeof value.expression.value === "string";
2260
- }
2261
- return value.expression.type === AST_NODE_TYPES.TemplateLiteral;
2262
- }
2250
+ var RULE_FEATURES39 = [
2251
+ "MOD"
2252
+ ];
2263
2253
  var no_string_refs_default = createRule({
2264
2254
  meta: {
2265
2255
  type: "problem",
2266
2256
  docs: {
2267
- description: "Disallow deprecated string `refs`.",
2257
+ description: "Replaces string refs with callback refs.",
2268
2258
  [Symbol.for("rule_features")]: RULE_FEATURES39
2269
2259
  },
2260
+ fixable: "code",
2270
2261
  messages: {
2271
2262
  noStringRefs: "[Deprecated] Use callback refs instead."
2272
2263
  },
@@ -2277,20 +2268,49 @@ var no_string_refs_default = createRule({
2277
2268
  defaultOptions: []
2278
2269
  });
2279
2270
  function create39(context) {
2271
+ const state = {
2272
+ isWithinClassComponent: false
2273
+ };
2274
+ function onClassBodyEnter(node) {
2275
+ if (ER21.isClassComponent(node.parent)) {
2276
+ state.isWithinClassComponent = true;
2277
+ }
2278
+ }
2279
+ function onClassBodyExit() {
2280
+ state.isWithinClassComponent = false;
2281
+ }
2280
2282
  return {
2283
+ ClassBody: onClassBodyEnter,
2284
+ "ClassBody:exit": onClassBodyExit,
2281
2285
  JSXAttribute(node) {
2282
- if (node.name.name !== "ref") {
2283
- return;
2284
- }
2285
- if (containsStringLiteral(node) || containsStringExpressionContainer(node)) {
2286
- context.report({
2287
- messageId: "noStringRefs",
2288
- node
2289
- });
2290
- }
2286
+ if (node.name.name !== "ref") return;
2287
+ const refNameText = getAttributeValueText(context, node.value);
2288
+ if (refNameText == null) return;
2289
+ context.report({
2290
+ messageId: "noStringRefs",
2291
+ node,
2292
+ fix(fixer) {
2293
+ if (node.value == null) return null;
2294
+ if (!state.isWithinClassComponent) return null;
2295
+ return fixer.replaceText(node.value, `{(ref) => { this.refs[${refNameText}] = ref; }}`);
2296
+ }
2297
+ });
2291
2298
  }
2292
2299
  };
2293
2300
  }
2301
+ function getAttributeValueText(context, node) {
2302
+ if (node == null) return null;
2303
+ switch (true) {
2304
+ case (node.type === AST_NODE_TYPES.Literal && typeof node.value === "string"):
2305
+ return context.sourceCode.getText(node);
2306
+ case (node.type === AST_NODE_TYPES.JSXExpressionContainer && node.expression.type === AST_NODE_TYPES.Literal && typeof node.expression.value === "string"):
2307
+ return context.sourceCode.getText(node.expression);
2308
+ case (node.type === AST_NODE_TYPES.JSXExpressionContainer && node.expression.type === AST_NODE_TYPES.TemplateLiteral):
2309
+ return context.sourceCode.getText(node.expression);
2310
+ default:
2311
+ return null;
2312
+ }
2313
+ }
2294
2314
  var RULE_NAME40 = "no-unsafe-component-will-mount";
2295
2315
  var RULE_FEATURES40 = [];
2296
2316
  function isUnsafeComponentWillMount(node) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "1.42.2-next.5",
3
+ "version": "1.43.0-beta.0",
4
4
  "description": "A set of composable ESLint rules for for libraries and frameworks that use React as a UI runtime.",
5
5
  "keywords": [
6
6
  "react",
@@ -50,13 +50,13 @@
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/core": "1.42.2-next.5",
54
- "@eslint-react/jsx": "1.42.2-next.5",
55
- "@eslint-react/eff": "1.42.2-next.5",
56
- "@eslint-react/ast": "1.42.2-next.5",
57
- "@eslint-react/kit": "1.42.2-next.5",
58
- "@eslint-react/shared": "1.42.2-next.5",
59
- "@eslint-react/var": "1.42.2-next.5"
53
+ "@eslint-react/core": "1.43.0-beta.0",
54
+ "@eslint-react/ast": "1.43.0-beta.0",
55
+ "@eslint-react/eff": "1.43.0-beta.0",
56
+ "@eslint-react/jsx": "1.43.0-beta.0",
57
+ "@eslint-react/var": "1.43.0-beta.0",
58
+ "@eslint-react/kit": "1.43.0-beta.0",
59
+ "@eslint-react/shared": "1.43.0-beta.0"
60
60
  },
61
61
  "devDependencies": {
62
62
  "@types/react": "^19.1.0",