oxlint-plugin-react-doctor 0.7.6-dev.8528def → 0.7.6-dev.8c9a6c4
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 +33 -10
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -14611,6 +14611,18 @@ const jsHoistRegexp = defineRule({
|
|
|
14611
14611
|
}, { treatIteratorCallbacksAsLoops: true })
|
|
14612
14612
|
});
|
|
14613
14613
|
//#endregion
|
|
14614
|
+
//#region src/plugin/utils/resolve-first-argument-binding.ts
|
|
14615
|
+
const resolveFirstArgumentBinding = (firstParameter) => {
|
|
14616
|
+
if (!firstParameter) return null;
|
|
14617
|
+
if (!isNodeOfType(firstParameter, "RestElement")) return firstParameter;
|
|
14618
|
+
if (!isNodeOfType(firstParameter.argument, "ArrayPattern")) return null;
|
|
14619
|
+
const elements = firstParameter.argument.elements ?? [];
|
|
14620
|
+
if (elements.length !== 1) return null;
|
|
14621
|
+
const firstBinding = elements[0];
|
|
14622
|
+
if (!firstBinding || isNodeOfType(firstBinding, "RestElement")) return null;
|
|
14623
|
+
return firstBinding;
|
|
14624
|
+
};
|
|
14625
|
+
//#endregion
|
|
14614
14626
|
//#region src/plugin/rules/js-performance/js-index-maps.ts
|
|
14615
14627
|
const referencesParameter = (expression, parameterName) => {
|
|
14616
14628
|
if (!expression) return false;
|
|
@@ -14621,7 +14633,7 @@ const referencesParameter = (expression, parameterName) => {
|
|
|
14621
14633
|
const isSingleFieldEqualityPredicate = (node) => {
|
|
14622
14634
|
const callback = node.arguments?.[0];
|
|
14623
14635
|
if (!isInlineFunctionExpression(callback)) return false;
|
|
14624
|
-
const firstParameter = callback.params?.[0];
|
|
14636
|
+
const firstParameter = resolveFirstArgumentBinding(callback.params?.[0]);
|
|
14625
14637
|
if (!firstParameter || !isNodeOfType(firstParameter, "Identifier")) return false;
|
|
14626
14638
|
let predicate = null;
|
|
14627
14639
|
const body = callback.body;
|
|
@@ -23043,10 +23055,15 @@ const isProp = (analysis, ref) => Boolean(ref.resolved?.defs.some((def) => {
|
|
|
23043
23055
|
if (!declaringNode) return false;
|
|
23044
23056
|
return isReactFunctionalComponent(declaringNode) && !isReactFunctionalHOC(analysis, declaringNode) || isCustomHook(declaringNode);
|
|
23045
23057
|
}));
|
|
23058
|
+
const isWholePropsParameterBinding = (bindingNode) => {
|
|
23059
|
+
if (isFunctionLike$1(bindingNode.parent)) return true;
|
|
23060
|
+
let declaringFunction = bindingNode.parent;
|
|
23061
|
+
while (declaringFunction && !isFunctionLike$1(declaringFunction)) declaringFunction = declaringFunction.parent;
|
|
23062
|
+
return Boolean(declaringFunction && resolveFirstArgumentBinding(declaringFunction.params?.[0]) === bindingNode);
|
|
23063
|
+
};
|
|
23046
23064
|
const isWholePropsObjectReference = (analysis, ref) => isProp(analysis, ref) && Boolean(ref.resolved?.defs.some((def) => {
|
|
23047
23065
|
if (def.type !== "Parameter") return false;
|
|
23048
|
-
|
|
23049
|
-
return isFunctionLike$1(bindingParent);
|
|
23066
|
+
return isWholePropsParameterBinding(def.name);
|
|
23050
23067
|
}));
|
|
23051
23068
|
const isIdentifierOrMemberExpression = (node) => isNodeOfType(node, "Identifier") || isNodeOfType(node, "MemberExpression");
|
|
23052
23069
|
const isPropAlias = (analysis, ref) => {
|
|
@@ -33028,11 +33045,13 @@ const noManyBooleanProps = defineRule({
|
|
|
33028
33045
|
};
|
|
33029
33046
|
const checkComponent = (functionNode, param, body, componentName, reportNode) => {
|
|
33030
33047
|
if (!param) return;
|
|
33048
|
+
const propsBinding = resolveFirstArgumentBinding(param);
|
|
33049
|
+
if (!propsBinding) return;
|
|
33031
33050
|
if (!functionContainsReactRenderOutput(functionNode, context.scopes)) return;
|
|
33032
|
-
if (isNodeOfType(
|
|
33051
|
+
if (isNodeOfType(propsBinding, "ObjectPattern")) {
|
|
33033
33052
|
const callbackUsedNames = collectCallbackUsedNames(body, param, context.scopes);
|
|
33034
33053
|
const booleanLikePropNames = [];
|
|
33035
|
-
for (const property of
|
|
33054
|
+
for (const property of propsBinding.properties ?? []) {
|
|
33036
33055
|
if (!isNodeOfType(property, "Property")) continue;
|
|
33037
33056
|
const keyName = isNodeOfType(property.key, "Identifier") ? property.key.name : null;
|
|
33038
33057
|
if (!keyName) continue;
|
|
@@ -33043,7 +33062,7 @@ const noManyBooleanProps = defineRule({
|
|
|
33043
33062
|
reportIfMany(booleanLikePropNames, componentName, reportNode);
|
|
33044
33063
|
return;
|
|
33045
33064
|
}
|
|
33046
|
-
if (isNodeOfType(
|
|
33065
|
+
if (isNodeOfType(propsBinding, "Identifier")) reportIfMany([...collectBooleanLikePropsFromBody(body, propsBinding.name)], componentName, reportNode);
|
|
33047
33066
|
};
|
|
33048
33067
|
return {
|
|
33049
33068
|
FunctionDeclaration(node) {
|
|
@@ -41804,8 +41823,9 @@ const CROSS_CUTTING_STATE_BOOLEAN_NAMES = new Set([
|
|
|
41804
41823
|
]);
|
|
41805
41824
|
const collectBooleanPropBindings = (param) => {
|
|
41806
41825
|
const bindings = /* @__PURE__ */ new Set();
|
|
41807
|
-
|
|
41808
|
-
|
|
41826
|
+
const propsBinding = resolveFirstArgumentBinding(param);
|
|
41827
|
+
if (!isNodeOfType(propsBinding, "ObjectPattern")) return bindings;
|
|
41828
|
+
for (const property of propsBinding.properties ?? []) {
|
|
41809
41829
|
if (!isNodeOfType(property, "Property")) continue;
|
|
41810
41830
|
if (property.computed) continue;
|
|
41811
41831
|
if (!isNodeOfType(property.key, "Identifier")) continue;
|
|
@@ -45547,8 +45567,11 @@ const collectFromObjectPattern = (pattern, bindings) => {
|
|
|
45547
45567
|
const collectDefaultedEmptyBindings = (functionNode) => {
|
|
45548
45568
|
const bindings = /* @__PURE__ */ new Map();
|
|
45549
45569
|
const params = functionNode.params ?? [];
|
|
45550
|
-
for (const param of params)
|
|
45551
|
-
|
|
45570
|
+
for (const [parameterIndex, param] of params.entries()) {
|
|
45571
|
+
const parameterBinding = parameterIndex === 0 ? resolveFirstArgumentBinding(param) : param;
|
|
45572
|
+
if (parameterBinding) collectFromObjectPattern(parameterBinding, bindings);
|
|
45573
|
+
}
|
|
45574
|
+
const propsParam = resolveFirstArgumentBinding(params[0]);
|
|
45552
45575
|
const body = functionNode.body;
|
|
45553
45576
|
if (!propsParam || !isNodeOfType(propsParam, "Identifier") || !body) return bindings;
|
|
45554
45577
|
if (!isNodeOfType(body, "BlockStatement")) return bindings;
|