oxlint-plugin-react-doctor 0.7.9-dev.d7d38d7 → 0.7.9-dev.e5d5753

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 +57 -40
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -19996,6 +19996,28 @@ const jsLengthCheckFirst = defineRule({
19996
19996
  } })
19997
19997
  });
19998
19998
  //#endregion
19999
+ //#region src/plugin/utils/is-proven-global-namespace-reference.ts
20000
+ const isProvenGlobalObjectReference = (expression, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
20001
+ const strippedExpression = stripParenExpression(expression);
20002
+ if (!isNodeOfType(strippedExpression, "Identifier")) return false;
20003
+ if ((strippedExpression.name === "globalThis" || strippedExpression.name === "window" || strippedExpression.name === "self" || strippedExpression.name === "global") && scopes.isGlobalReference(strippedExpression)) return true;
20004
+ const symbol = scopes.symbolFor(strippedExpression);
20005
+ if (!symbol?.initializer || symbol.kind !== "const" || visitedSymbolIds.has(symbol.id)) return false;
20006
+ visitedSymbolIds.add(symbol.id);
20007
+ return isProvenGlobalObjectReference(symbol.initializer, scopes, visitedSymbolIds);
20008
+ };
20009
+ const isProvenGlobalNamespaceReference = (expression, namespaceName, scopes, visitedSymbolIds = /* @__PURE__ */ new Set()) => {
20010
+ const strippedExpression = stripParenExpression(expression);
20011
+ if (isNodeOfType(strippedExpression, "Identifier")) {
20012
+ if (strippedExpression.name === namespaceName && scopes.isGlobalReference(strippedExpression)) return true;
20013
+ const symbol = scopes.symbolFor(strippedExpression);
20014
+ if (!symbol?.initializer || symbol.kind !== "const" || visitedSymbolIds.has(symbol.id)) return false;
20015
+ visitedSymbolIds.add(symbol.id);
20016
+ return isProvenGlobalNamespaceReference(symbol.initializer, namespaceName, scopes, visitedSymbolIds);
20017
+ }
20018
+ return isNodeOfType(strippedExpression, "MemberExpression") && getStaticPropertyName(strippedExpression) === namespaceName && isProvenGlobalObjectReference(strippedExpression.object, scopes);
20019
+ };
20020
+ //#endregion
19999
20021
  //#region src/plugin/rules/js-performance/js-min-max-loop.ts
20000
20022
  const builtinMutationByProgram = /* @__PURE__ */ new WeakMap();
20001
20023
  const RUNTIMELESS_SYMBOL_KINDS = new Set(["ts-interface", "ts-type-alias"]);
@@ -20052,26 +20074,6 @@ const isSafeFreshNumericArray = (arrayExpression) => {
20052
20074
  }
20053
20075
  return !(didFindPositiveZero && didFindNegativeZero);
20054
20076
  };
20055
- const isGlobalObjectReference = (expression, scopes, visitedSymbols = /* @__PURE__ */ new Set()) => {
20056
- const strippedExpression = stripParenExpression(expression);
20057
- if (!isNodeOfType(strippedExpression, "Identifier")) return false;
20058
- if ((strippedExpression.name === "globalThis" || strippedExpression.name === "window" || strippedExpression.name === "self" || strippedExpression.name === "global") && scopes.isGlobalReference(strippedExpression)) return true;
20059
- const symbol = scopes.symbolFor(strippedExpression);
20060
- if (!symbol?.initializer || symbol.kind !== "const" || visitedSymbols.has(symbol.id)) return false;
20061
- visitedSymbols.add(symbol.id);
20062
- return isGlobalObjectReference(symbol.initializer, scopes, visitedSymbols);
20063
- };
20064
- const resolvesToGlobalNamespace = (expression, namespaceName, scopes, visitedSymbols = /* @__PURE__ */ new Set()) => {
20065
- const strippedExpression = stripParenExpression(expression);
20066
- if (isNodeOfType(strippedExpression, "Identifier")) {
20067
- if (strippedExpression.name === namespaceName && scopes.isGlobalReference(strippedExpression)) return true;
20068
- const symbol = scopes.symbolFor(strippedExpression);
20069
- if (!symbol?.initializer || symbol.kind !== "const" || visitedSymbols.has(symbol.id)) return false;
20070
- visitedSymbols.add(symbol.id);
20071
- return resolvesToGlobalNamespace(symbol.initializer, namespaceName, scopes, visitedSymbols);
20072
- }
20073
- return isNodeOfType(strippedExpression, "MemberExpression") && getStaticPropertyName(strippedExpression) === namespaceName && isGlobalObjectReference(strippedExpression.object, scopes);
20074
- };
20075
20077
  const resolvesToGlobalMethod = (expression, namespaceName, methodNames, scopes, visitedSymbols = /* @__PURE__ */ new Set()) => {
20076
20078
  const strippedExpression = stripParenExpression(expression);
20077
20079
  if (isNodeOfType(strippedExpression, "Identifier")) {
@@ -20080,7 +20082,7 @@ const resolvesToGlobalMethod = (expression, namespaceName, methodNames, scopes,
20080
20082
  visitedSymbols.add(symbol.id);
20081
20083
  return resolvesToGlobalMethod(symbol.initializer, namespaceName, methodNames, scopes, visitedSymbols);
20082
20084
  }
20083
- return isNodeOfType(strippedExpression, "MemberExpression") && methodNames.has(getStaticPropertyName(strippedExpression) ?? "") && resolvesToGlobalNamespace(strippedExpression.object, namespaceName, scopes);
20085
+ return isNodeOfType(strippedExpression, "MemberExpression") && methodNames.has(getStaticPropertyName(strippedExpression) ?? "") && isProvenGlobalNamespaceReference(strippedExpression.object, namespaceName, scopes);
20084
20086
  };
20085
20087
  const resolvesToNativeArrayPrototype = (expression, scopes, visitedSymbols = /* @__PURE__ */ new Set()) => {
20086
20088
  const strippedExpression = stripParenExpression(expression);
@@ -20092,7 +20094,7 @@ const resolvesToNativeArrayPrototype = (expression, scopes, visitedSymbols = /*
20092
20094
  }
20093
20095
  if (isNodeOfType(strippedExpression, "MemberExpression")) {
20094
20096
  const propertyName = getStaticPropertyName(strippedExpression);
20095
- if (propertyName === "prototype") return resolvesToGlobalNamespace(strippedExpression.object, "Array", scopes);
20097
+ if (propertyName === "prototype") return isProvenGlobalNamespaceReference(strippedExpression.object, "Array", scopes);
20096
20098
  return propertyName === "__proto__" && isNodeOfType(stripParenExpression(strippedExpression.object), "ArrayExpression");
20097
20099
  }
20098
20100
  if (!isNodeOfType(strippedExpression, "CallExpression")) return false;
@@ -20103,23 +20105,23 @@ const resolvesToNativeArrayPrototype = (expression, scopes, visitedSymbols = /*
20103
20105
  const isGlobalNamespaceReplacementTarget = (target, namespaceName, scopes) => {
20104
20106
  const strippedTarget = stripParenExpression(target);
20105
20107
  if (isNodeOfType(strippedTarget, "Identifier")) return strippedTarget.name === namespaceName && scopes.isGlobalReference(strippedTarget);
20106
- return isNodeOfType(strippedTarget, "MemberExpression") && getStaticPropertyName(strippedTarget) === namespaceName && isGlobalObjectReference(strippedTarget.object, scopes);
20108
+ return isNodeOfType(strippedTarget, "MemberExpression") && getStaticPropertyName(strippedTarget) === namespaceName && isProvenGlobalObjectReference(strippedTarget.object, scopes);
20107
20109
  };
20108
20110
  const isUnsafeBuiltinMemberTarget = (target, targetFunction, scopes) => {
20109
20111
  const strippedTarget = stripParenExpression(target);
20110
20112
  if (!isNodeOfType(strippedTarget, "MemberExpression")) return false;
20111
20113
  const propertyName = getStaticPropertyName(strippedTarget);
20112
20114
  if (resolvesToNativeArrayPrototype(strippedTarget.object, scopes)) return propertyName === null || propertyName === "sort";
20113
- if (resolvesToGlobalNamespace(strippedTarget.object, "Math", scopes)) return propertyName === null || propertyName === targetFunction;
20114
- return isGlobalObjectReference(strippedTarget.object, scopes) && (propertyName === null || propertyName === "Math");
20115
+ if (isProvenGlobalNamespaceReference(strippedTarget.object, "Math", scopes)) return propertyName === null || propertyName === targetFunction;
20116
+ return isProvenGlobalObjectReference(strippedTarget.object, scopes) && (propertyName === null || propertyName === "Math");
20115
20117
  };
20116
20118
  const isUnsafeBuiltinMutationApiCall = (callExpression, targetFunction, scopes) => {
20117
20119
  const target = callExpression.arguments[0];
20118
20120
  if (!target) return false;
20119
20121
  let propertyName = null;
20120
20122
  if (resolvesToNativeArrayPrototype(target, scopes)) propertyName = "sort";
20121
- else if (resolvesToGlobalNamespace(target, "Math", scopes)) propertyName = targetFunction;
20122
- else if (isGlobalObjectReference(target, scopes)) propertyName = "Math";
20123
+ else if (isProvenGlobalNamespaceReference(target, "Math", scopes)) propertyName = targetFunction;
20124
+ else if (isProvenGlobalObjectReference(target, scopes)) propertyName = "Math";
20123
20125
  if (!propertyName) return false;
20124
20126
  const canObjectExpressionSetProperty = (properties) => {
20125
20127
  if (!isNodeOfType(properties, "ObjectExpression")) return true;
@@ -20170,7 +20172,7 @@ const hasUnsafeMathBinding = (node, scopes) => {
20170
20172
  let scope = scopes.scopeFor(node);
20171
20173
  while (scope) {
20172
20174
  const symbol = scope.symbolsByName.get("Math");
20173
- if (symbol && !RUNTIMELESS_SYMBOL_KINDS.has(symbol.kind)) return !(symbol.kind === "const" && symbol.initializer && resolvesToGlobalNamespace(symbol.initializer, "Math", scopes));
20175
+ if (symbol && !RUNTIMELESS_SYMBOL_KINDS.has(symbol.kind)) return !(symbol.kind === "const" && symbol.initializer && isProvenGlobalNamespaceReference(symbol.initializer, "Math", scopes));
20174
20176
  scope = scope.parent;
20175
20177
  }
20176
20178
  return false;
@@ -51558,6 +51560,31 @@ const preferModuleScopePureFunction = defineRule({
51558
51560
  }
51559
51561
  });
51560
51562
  //#endregion
51563
+ //#region src/plugin/utils/get-require-call-source.ts
51564
+ const getRequireCallSource = (expression) => {
51565
+ const unwrappedExpression = stripParenExpression(expression);
51566
+ if (isNodeOfType(unwrappedExpression, "MemberExpression")) return getRequireCallSource(unwrappedExpression.object);
51567
+ if (!isNodeOfType(unwrappedExpression, "CallExpression")) return null;
51568
+ if (!isNodeOfType(unwrappedExpression.callee, "Identifier") || unwrappedExpression.callee.name !== "require") return null;
51569
+ const [firstArgument] = unwrappedExpression.arguments ?? [];
51570
+ if (!firstArgument || !isNodeOfType(firstArgument, "Literal")) return null;
51571
+ return typeof firstArgument.value === "string" ? firstArgument.value : null;
51572
+ };
51573
+ //#endregion
51574
+ //#region src/plugin/utils/is-proven-node-crypto-namespace-reference.ts
51575
+ const NODE_CRYPTO_MODULE_SOURCES = new Set(["crypto", "node:crypto"]);
51576
+ const isProvenNodeCryptoNamespaceReference = (expression, scopes) => {
51577
+ const identifier = stripParenExpression(expression);
51578
+ if (!isNodeOfType(identifier, "Identifier")) return false;
51579
+ const symbol = resolveConstIdentifierAlias(identifier, scopes);
51580
+ if (!symbol) return false;
51581
+ if (symbol.kind === "import") {
51582
+ const importBinding = getImportBindingForName(identifier, symbol.name);
51583
+ return Boolean(importBinding && NODE_CRYPTO_MODULE_SOURCES.has(importBinding.source));
51584
+ }
51585
+ return Boolean(symbol.kind === "const" && symbol.initializer && NODE_CRYPTO_MODULE_SOURCES.has(getRequireCallSource(symbol.initializer) ?? ""));
51586
+ };
51587
+ //#endregion
51561
51588
  //#region src/plugin/rules/architecture/prefer-module-scope-static-value.ts
51562
51589
  const MUTATING_RECEIVER_METHOD_NAMES = new Set([...MUTATING_ARRAY_METHODS, ...MUTATING_COLLECTION_METHODS]);
51563
51590
  const isMutationContext = (referenceIdentifier) => {
@@ -51671,9 +51698,9 @@ const isImpureCall = (node, scopes) => {
51671
51698
  const callee = node.callee;
51672
51699
  if (isNodeOfType(callee, "Identifier")) return isImpureBareCallee(callee, scopes);
51673
51700
  if (!isNodeOfType(callee, "MemberExpression") || callee.computed) return false;
51674
- if (!isNodeOfType(callee.object, "Identifier")) return false;
51675
51701
  if (!isNodeOfType(callee.property, "Identifier")) return false;
51676
- return Boolean(IMPURE_MEMBER_RECEIVERS.get(callee.object.name)?.has(callee.property.name));
51702
+ for (const [receiverName, receiverMethodNames] of IMPURE_MEMBER_RECEIVERS) if (receiverMethodNames.has(callee.property.name) && (isProvenGlobalNamespaceReference(callee.object, receiverName, scopes) || receiverName === "crypto" && isProvenNodeCryptoNamespaceReference(callee.object, scopes))) return true;
51703
+ return false;
51677
51704
  };
51678
51705
  const containsImpureExpression = (expression, scopes) => {
51679
51706
  let foundImpure = false;
@@ -56442,16 +56469,6 @@ const rnListCallbackPerRow = defineRule({
56442
56469
  }
56443
56470
  });
56444
56471
  //#endregion
56445
- //#region src/plugin/utils/get-require-call-source.ts
56446
- const getRequireCallSource = (expression) => {
56447
- if (isNodeOfType(expression, "MemberExpression")) return getRequireCallSource(expression.object);
56448
- if (!isNodeOfType(expression, "CallExpression")) return null;
56449
- if (!isNodeOfType(expression.callee, "Identifier") || expression.callee.name !== "require") return null;
56450
- const [firstArgument] = expression.arguments ?? [];
56451
- if (!firstArgument || !isNodeOfType(firstArgument, "Literal")) return null;
56452
- return typeof firstArgument.value === "string" ? firstArgument.value : null;
56453
- };
56454
- //#endregion
56455
56472
  //#region src/plugin/utils/get-initializer-module-source.ts
56456
56473
  const getInitializerModuleSource = (contextNode, initializer) => {
56457
56474
  const requireSource = getRequireCallSource(initializer);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-plugin-react-doctor",
3
- "version": "0.7.9-dev.d7d38d7",
3
+ "version": "0.7.9-dev.e5d5753",
4
4
  "description": "React Doctor rules for oxlint.",
5
5
  "keywords": [
6
6
  "accessibility",