diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/isEnumValue.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/isEnumValue.ts index c158335a..398b0792 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/helpers/isEnumValue.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/helpers/isEnumValue.ts @@ -3,21 +3,31 @@ import { propertyNameMatches } from "./propertyNameMatches"; import { Rule } from "eslint"; /** Checks whether an enum node (MemberExpression), e.g. ButtonVariant["primary"] - * has a given enumName ("ButtonVariant") and a given propertyName ("primary") */ + * has a given enumName ("ButtonVariant") and a given propertyName ("primary"), or one of given property names. */ export function isEnumValue( context: Rule.RuleContext, enumExpression: MemberExpression, enumName: string, - propertyName: string + propertyName: string | string[] ) { - return ( + if ( enumExpression.object?.type === "Identifier" && - enumExpression.object.name === enumName && - propertyNameMatches( - context, - enumExpression.property, - enumExpression.computed, - propertyName - ) - ); + enumExpression.object.name === enumName + ) { + const nameMatches = (name: string) => + propertyNameMatches( + context, + enumExpression.property, + enumExpression.computed, + name + ); + + if (Array.isArray(propertyName)) { + return propertyName.some((name) => nameMatches(name)); + } + + return nameMatches(propertyName); + } + + return false; }