eslint-plugin-react-x 2.3.10-next.1 → 2.3.10-next.2

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 +19 -4
  2. package/package.json +7 -7
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { DEFAULT_ESLINT_REACT_SETTINGS, WEBSITE_URL, coerceSettings, getConfigAdapters, getSettingsFromContext, report, toRegExp } from "@eslint-react/shared";
2
2
  import { AST_NODE_TYPES } from "@typescript-eslint/types";
3
3
  import { ESLintUtils } from "@typescript-eslint/utils";
4
- import { isFalseLiteralType, isTrueLiteralType, isTypeFlagSet, unionConstituents } from "ts-api-utils";
4
+ import { isFalseLiteralType, isPropertyReadonlyInType, isTrueLiteralType, isTypeFlagSet, unionConstituents } from "ts-api-utils";
5
5
  import { P, isMatching, match } from "ts-pattern";
6
6
  import ts from "typescript";
7
7
  import * as AST from "@eslint-react/ast";
@@ -34,7 +34,7 @@ var __export = (all, symbols) => {
34
34
  //#endregion
35
35
  //#region package.json
36
36
  var name$6 = "eslint-plugin-react-x";
37
- var version = "2.3.10-next.1";
37
+ var version = "2.3.10-next.2";
38
38
 
39
39
  //#endregion
40
40
  //#region src/utils/create-rule.ts
@@ -3451,6 +3451,7 @@ var prefer_read_only_props_default = createRule({
3451
3451
  });
3452
3452
  function create$2(context) {
3453
3453
  const services = ESLintUtils.getParserServices(context, false);
3454
+ const checker = services.program.getTypeChecker();
3454
3455
  const { ctx, listeners } = useComponentCollector(context);
3455
3456
  return {
3456
3457
  ...listeners,
@@ -3461,7 +3462,10 @@ function create$2(context) {
3461
3462
  if (component.name == null) continue;
3462
3463
  const [props] = component.node.params;
3463
3464
  if (props == null) continue;
3464
- if (isTypeReadonlyLoose(services, getConstrainedTypeAtLocation(services, props))) continue;
3465
+ const propsType = getConstrainedTypeAtLocation(services, props);
3466
+ if (isTypeReadonly(services.program, propsType)) continue;
3467
+ if (isTypeReadonlyLoose(services, propsType)) continue;
3468
+ if (propsType.isClassOrInterface() && isClassOrInterfaceReadonlyLoose(checker, propsType)) continue;
3465
3469
  context.report({
3466
3470
  messageId: "preferReadOnlyProps",
3467
3471
  node: props
@@ -3471,7 +3475,6 @@ function create$2(context) {
3471
3475
  };
3472
3476
  }
3473
3477
  function isTypeReadonlyLoose(services, type) {
3474
- if (isTypeReadonly(services.program, type)) return true;
3475
3478
  try {
3476
3479
  const im = getTypeImmutability(services.program, type);
3477
3480
  return isUnknown(im) || isImmutable(im) || isReadonlyShallow(im) || isReadonlyDeep(im);
@@ -3479,6 +3482,18 @@ function isTypeReadonlyLoose(services, type) {
3479
3482
  return true;
3480
3483
  }
3481
3484
  }
3485
+ function isClassOrInterfaceReadonlyLoose(checker, type) {
3486
+ const baseTypes = type.getBaseTypes() ?? [];
3487
+ const properties = type.getProperties();
3488
+ if (properties.length === 0) return true;
3489
+ if (baseTypes.length === 0) return properties.every((property) => isPropertyReadonlyInType(type, property.getEscapedName(), checker));
3490
+ for (const property of properties) {
3491
+ const propertyName = property.getEscapedName();
3492
+ if (isPropertyReadonlyInType(type, propertyName, checker)) continue;
3493
+ else if (baseTypes.length > 0) return baseTypes.every((heritageType) => isPropertyReadonlyInType(heritageType, propertyName, checker));
3494
+ }
3495
+ return true;
3496
+ }
3482
3497
 
3483
3498
  //#endregion
3484
3499
  //#region src/rules/prefer-use-state-lazy-initialization.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "eslint-plugin-react-x",
3
- "version": "2.3.10-next.1",
3
+ "version": "2.3.10-next.2",
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",
@@ -46,16 +46,16 @@
46
46
  "string-ts": "^2.3.1",
47
47
  "ts-api-utils": "^2.1.0",
48
48
  "ts-pattern": "^5.9.0",
49
- "@eslint-react/ast": "2.3.10-next.1",
50
- "@eslint-react/shared": "2.3.10-next.1",
51
- "@eslint-react/core": "2.3.10-next.1",
52
- "@eslint-react/var": "2.3.10-next.1",
53
- "@eslint-react/eff": "2.3.10-next.1"
49
+ "@eslint-react/ast": "2.3.10-next.2",
50
+ "@eslint-react/eff": "2.3.10-next.2",
51
+ "@eslint-react/core": "2.3.10-next.2",
52
+ "@eslint-react/shared": "2.3.10-next.2",
53
+ "@eslint-react/var": "2.3.10-next.2"
54
54
  },
55
55
  "devDependencies": {
56
56
  "@types/react": "^19.2.7",
57
57
  "@types/react-dom": "^19.2.3",
58
- "tsdown": "^0.17.0-beta.3",
58
+ "tsdown": "^0.17.0-beta.4",
59
59
  "@local/configs": "0.0.0"
60
60
  },
61
61
  "peerDependencies": {