oxlint-plugin-react-doctor 0.5.8-dev.ba2af1b → 0.5.8-dev.c72b560
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 +15 -5
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10789,10 +10789,22 @@ const isWithinChildrenToArray = (jsxNode) => {
|
|
|
10789
10789
|
}
|
|
10790
10790
|
return false;
|
|
10791
10791
|
};
|
|
10792
|
+
const spreadCanOverwriteKey = (spreadAttribute) => {
|
|
10793
|
+
const argument = spreadAttribute.argument;
|
|
10794
|
+
if (!isNodeOfType(argument, "ObjectExpression")) return true;
|
|
10795
|
+
for (const property of argument.properties) {
|
|
10796
|
+
if (!isNodeOfType(property, "Property")) return true;
|
|
10797
|
+
if (property.computed) return true;
|
|
10798
|
+
const propertyKey = property.key;
|
|
10799
|
+
if (isNodeOfType(propertyKey, "Identifier") && propertyKey.name === "key") return true;
|
|
10800
|
+
if (isNodeOfType(propertyKey, "Literal") && String(propertyKey.value) === "key") return true;
|
|
10801
|
+
}
|
|
10802
|
+
return false;
|
|
10803
|
+
};
|
|
10792
10804
|
const checkKeyBeforeSpread = (context, openingElement) => {
|
|
10793
10805
|
let keyIndex = null;
|
|
10794
10806
|
let keyAttribute = null;
|
|
10795
|
-
let
|
|
10807
|
+
let lastOverwritingSpreadIndex = null;
|
|
10796
10808
|
for (let attributeIndex = 0; attributeIndex < openingElement.attributes.length; attributeIndex++) {
|
|
10797
10809
|
const attribute = openingElement.attributes[attributeIndex];
|
|
10798
10810
|
if (isNodeOfType(attribute, "JSXAttribute")) {
|
|
@@ -10800,11 +10812,9 @@ const checkKeyBeforeSpread = (context, openingElement) => {
|
|
|
10800
10812
|
keyIndex = attributeIndex;
|
|
10801
10813
|
keyAttribute = attribute;
|
|
10802
10814
|
}
|
|
10803
|
-
} else if (isNodeOfType(attribute, "JSXSpreadAttribute"))
|
|
10804
|
-
if (firstSpreadIndex === null) firstSpreadIndex = attributeIndex;
|
|
10805
|
-
}
|
|
10815
|
+
} else if (isNodeOfType(attribute, "JSXSpreadAttribute") && spreadCanOverwriteKey(attribute)) lastOverwritingSpreadIndex = attributeIndex;
|
|
10806
10816
|
}
|
|
10807
|
-
if (keyIndex !== null &&
|
|
10817
|
+
if (keyIndex !== null && lastOverwritingSpreadIndex !== null && lastOverwritingSpreadIndex > keyIndex && keyAttribute) context.report({
|
|
10808
10818
|
node: keyAttribute,
|
|
10809
10819
|
message: KEY_BEFORE_SPREAD
|
|
10810
10820
|
});
|