Skip to content

Commit 5ffcb4f

Browse files
committed
make use of some helper functions
Signed-off-by: gitdallas <[email protected]>
1 parent 3a78c06 commit 5ffcb4f

File tree

1 file changed

+7
-11
lines changed

1 file changed

+7
-11
lines changed

packages/eslint-plugin-pf-codemods/src/rules/v6/enableAnimations/enable-animations.ts

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { Rule } from "eslint";
22
import { JSXOpeningElement, JSXAttribute } from "estree-jsx";
33
import { getFromPackage, checkMatchingJSXOpeningElement } from "../../helpers";
4+
import { getAttribute, getAttributeValue } from "../../helpers/JSXAttributes";
45

56
// Rule to add hasAnimations prop to components that support animations
67
module.exports = {
@@ -44,12 +45,7 @@ module.exports = {
4445

4546
// Helper function to check if isTree prop exists and isn't explicitly false
4647
function hasValidIsTreeProp(node: JSXOpeningElement): boolean {
47-
const isTreeAttribute = node.attributes.find(
48-
(attr) =>
49-
attr.type === "JSXAttribute" &&
50-
attr.name.type === "JSXIdentifier" &&
51-
attr.name.name === "isTree"
52-
) as JSXAttribute | undefined;
48+
const isTreeAttribute = getAttribute(node, "isTree");
5349

5450
if (!isTreeAttribute) {
5551
return false; // No isTree prop found
@@ -60,12 +56,12 @@ module.exports = {
6056
return true;
6157
}
6258

59+
// Get the actual value using the helper
60+
const attributeValue = getAttributeValue(context, isTreeAttribute.value);
61+
6362
// Check for explicit false: isTree={false}
64-
if (isTreeAttribute.value.type === "JSXExpressionContainer") {
65-
const expression = isTreeAttribute.value.expression;
66-
if (expression.type === "Literal" && expression.value === false) {
67-
return false;
68-
}
63+
if (attributeValue.type === "Literal" && attributeValue.value === false) {
64+
return false;
6965
}
7066

7167
// For anything else (including complex expressions), assume it could be truthy

0 commit comments

Comments
 (0)