oxlint-plugin-react-doctor 0.7.1-dev.160f84c → 0.7.1-dev.1880b15
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 +22 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -549,6 +549,12 @@ const INDEX_PARAMETER_NAMES = new Set([
|
|
|
549
549
|
"idx",
|
|
550
550
|
"i"
|
|
551
551
|
]);
|
|
552
|
+
const REACT_RUNTIME_MODULE_SOURCES = new Set([
|
|
553
|
+
"react",
|
|
554
|
+
"react-dom",
|
|
555
|
+
"preact/compat",
|
|
556
|
+
"preact/hooks"
|
|
557
|
+
]);
|
|
552
558
|
const LOADING_STATE_PATTERN = /^(?:isLoading|isPending)$/;
|
|
553
559
|
const STABLE_HOOK_WRAPPERS = new Set([
|
|
554
560
|
"useState",
|
|
@@ -21606,6 +21612,13 @@ const noEffectEventHandler = defineRule({
|
|
|
21606
21612
|
}
|
|
21607
21613
|
});
|
|
21608
21614
|
//#endregion
|
|
21615
|
+
//#region src/plugin/utils/is-imported-from-non-react-module.ts
|
|
21616
|
+
const isImportedFromNonReactModule = (contextNode, localIdentifierName) => {
|
|
21617
|
+
const importSource = getImportSourceForName(contextNode, localIdentifierName);
|
|
21618
|
+
if (importSource === null) return false;
|
|
21619
|
+
return !REACT_RUNTIME_MODULE_SOURCES.has(importSource);
|
|
21620
|
+
};
|
|
21621
|
+
//#endregion
|
|
21609
21622
|
//#region src/plugin/rules/state-and-effects/no-effect-event-in-deps.ts
|
|
21610
21623
|
const createComponentBindingStackTracker = (callbacks) => {
|
|
21611
21624
|
const componentBindingStack = [];
|
|
@@ -21659,6 +21672,7 @@ const noEffectEventInDeps = defineRule({
|
|
|
21659
21672
|
const initializer = declaratorNode.init;
|
|
21660
21673
|
if (!initializer || !isNodeOfType(initializer, "CallExpression")) return;
|
|
21661
21674
|
if (!isHookCall$1(initializer, "useEffectEvent")) return;
|
|
21675
|
+
if (isNodeOfType(initializer.callee, "Identifier") && isImportedFromNonReactModule(declaratorNode, initializer.callee.name)) return;
|
|
21662
21676
|
componentBindings.addBindingToCurrentFrame(declaratorNode.id.name);
|
|
21663
21677
|
} });
|
|
21664
21678
|
return {
|
|
@@ -39395,6 +39409,12 @@ const isUseEffectEventSymbol = (symbol) => {
|
|
|
39395
39409
|
if (!initializer || !isNodeOfType(initializer, "CallExpression")) return false;
|
|
39396
39410
|
return getHookNameFromCallee(initializer.callee) === "useEffectEvent";
|
|
39397
39411
|
};
|
|
39412
|
+
const isNonReactEffectEventCallee = (callee, contextNode) => isNodeOfType(callee, "Identifier") && isImportedFromNonReactModule(contextNode, callee.name);
|
|
39413
|
+
const isNonReactEffectEventSymbol = (symbol, contextNode) => {
|
|
39414
|
+
const initializer = symbol.initializer;
|
|
39415
|
+
if (!initializer || !isNodeOfType(initializer, "CallExpression")) return false;
|
|
39416
|
+
return isNonReactEffectEventCallee(initializer.callee, contextNode);
|
|
39417
|
+
};
|
|
39398
39418
|
const findEnclosingComponentOrHookFunction = (node) => {
|
|
39399
39419
|
let current = node.parent;
|
|
39400
39420
|
while (current) {
|
|
@@ -39448,7 +39468,7 @@ const rulesOfHooks = defineRule({
|
|
|
39448
39468
|
const hookContext = isHookCall(node, context.scopes, settings);
|
|
39449
39469
|
if (!hookContext) return;
|
|
39450
39470
|
const { hookName } = hookContext;
|
|
39451
|
-
if (hookName === "useEffectEvent" && !isUseEffectEventInitializer(node)) {
|
|
39471
|
+
if (hookName === "useEffectEvent" && !isUseEffectEventInitializer(node) && !isNonReactEffectEventCallee(node.callee, node)) {
|
|
39452
39472
|
context.report({
|
|
39453
39473
|
node: node.callee,
|
|
39454
39474
|
message: buildEffectEventPassedDownMessage()
|
|
@@ -39558,6 +39578,7 @@ const rulesOfHooks = defineRule({
|
|
|
39558
39578
|
Identifier(node) {
|
|
39559
39579
|
const symbol = context.scopes.referenceFor(node)?.resolvedSymbol;
|
|
39560
39580
|
if (!symbol || !isUseEffectEventSymbol(symbol)) return;
|
|
39581
|
+
if (isNonReactEffectEventSymbol(symbol, node)) return;
|
|
39561
39582
|
if (!isSameComponentOrHookScope(symbol, node)) return;
|
|
39562
39583
|
if (isInsideAllowedEffectEventCallback(node, additionalEffectHooksRegex)) return;
|
|
39563
39584
|
context.report({
|