oxlint-plugin-react-doctor 0.5.1-dev.fee3fc4 → 0.5.2-dev.022790b

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 +35 -19
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -5839,6 +5839,20 @@ const isReactHookName = (name) => {
5839
5839
  //#region src/plugin/utils/is-react-component-or-hook-name.ts
5840
5840
  const isReactComponentOrHookName = (name) => isReactComponentName(name) || isReactHookName(name);
5841
5841
  //#endregion
5842
+ //#region src/plugin/utils/is-react-hoc-callback-argument.ts
5843
+ const reactHocCalleeName = (callee) => {
5844
+ if (isNodeOfType(callee, "Identifier")) return callee.name;
5845
+ if (isNodeOfType(callee, "MemberExpression") && !callee.computed && isNodeOfType(callee.object, "Identifier") && callee.object.name === "React" && isNodeOfType(callee.property, "Identifier")) return `React.${callee.property.name}`;
5846
+ return null;
5847
+ };
5848
+ const isReactHocCallbackArgument = (functionNode) => {
5849
+ const parent = functionNode.parent;
5850
+ if (!parent || !isNodeOfType(parent, "CallExpression")) return false;
5851
+ if (parent.arguments[0] !== functionNode) return false;
5852
+ const calleeName = reactHocCalleeName(parent.callee);
5853
+ return calleeName !== null && REACT_HOC_NAMES.has(calleeName);
5854
+ };
5855
+ //#endregion
5842
5856
  //#region src/plugin/rules/react-builtins/exhaustive-deps-low-level.ts
5843
5857
  /**
5844
5858
  * Lowest-level helpers consumed by both the main `exhaustive-deps`
@@ -6069,6 +6083,7 @@ const findEnclosingComponentOrHookFunction$1 = (node) => {
6069
6083
  let current = node.parent;
6070
6084
  while (current) {
6071
6085
  if (isNodeOfType(current, "FunctionDeclaration") || isNodeOfType(current, "FunctionExpression") || isNodeOfType(current, "ArrowFunctionExpression")) {
6086
+ if (isReactHocCallbackArgument(current)) return current;
6072
6087
  const functionName = inferFunctionName$1(current);
6073
6088
  if (functionName && isReactComponentOrHookName(functionName)) return current;
6074
6089
  }
@@ -33180,7 +33195,7 @@ const findEnclosingFunctionInfo = (node) => {
33180
33195
  name: displayName,
33181
33196
  hasResolvedName: resolvedName !== null,
33182
33197
  isAsync: Boolean(current.async),
33183
- isComponentOrHook: resolvedName === null ? false : isReactComponentOrHookName(displayName)
33198
+ isComponentOrHook: isReactHocCallbackArgument(current) || (resolvedName === null ? false : isReactComponentOrHookName(displayName))
33184
33199
  };
33185
33200
  }
33186
33201
  current = current.parent ?? null;
@@ -33239,6 +33254,7 @@ const findEnclosingComponentOrHookFunction = (node) => {
33239
33254
  let current = node.parent;
33240
33255
  while (current) {
33241
33256
  if (isFunctionLike$2(current)) {
33257
+ if (isReactHocCallbackArgument(current)) return current;
33242
33258
  const resolvedName = inferFunctionName(current);
33243
33259
  if (resolvedName !== null && isReactComponentOrHookName(resolvedName)) return current;
33244
33260
  }
@@ -33338,26 +33354,26 @@ const rulesOfHooks = defineRule({
33338
33354
  });
33339
33355
  return;
33340
33356
  }
33341
- if (!enclosing.hasResolvedName) {
33342
- let outerWalker = enclosing.node;
33343
- let outerIsComponentOrHook = false;
33344
- while (outerWalker) {
33345
- const outerInfo = findEnclosingFunctionInfo(outerWalker);
33346
- if (!outerInfo) break;
33347
- if (outerInfo.isComponentOrHook) {
33348
- outerIsComponentOrHook = true;
33349
- break;
33357
+ if (!enclosing.isComponentOrHook) {
33358
+ if (!enclosing.hasResolvedName) {
33359
+ let outerWalker = enclosing.node;
33360
+ let outerIsComponentOrHook = false;
33361
+ while (outerWalker) {
33362
+ const outerInfo = findEnclosingFunctionInfo(outerWalker);
33363
+ if (!outerInfo) break;
33364
+ if (outerInfo.isComponentOrHook) {
33365
+ outerIsComponentOrHook = true;
33366
+ break;
33367
+ }
33368
+ outerWalker = outerInfo.node;
33350
33369
  }
33351
- outerWalker = outerInfo.node;
33370
+ if (!outerIsComponentOrHook) return;
33371
+ context.report({
33372
+ node: node.callee,
33373
+ message: buildConditionalMessage(hookName)
33374
+ });
33375
+ return;
33352
33376
  }
33353
- if (!outerIsComponentOrHook) return;
33354
- context.report({
33355
- node: node.callee,
33356
- message: buildConditionalMessage(hookName)
33357
- });
33358
- return;
33359
- }
33360
- if (!enclosing.isComponentOrHook) {
33361
33377
  context.report({
33362
33378
  node: node.callee,
33363
33379
  message: buildNonComponentMessage(hookName, enclosing.name)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "oxlint-plugin-react-doctor",
3
- "version": "0.5.1-dev.fee3fc4",
3
+ "version": "0.5.2-dev.022790b",
4
4
  "description": "oxlint plugin for React Doctor: diagnose React codebases for security, performance, correctness, accessibility, bundle-size, and architecture issues",
5
5
  "keywords": [
6
6
  "accessibility",