From f8521a2d07057d416a49c8e354f0002082342c50 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 15 Apr 2024 08:30:45 -0400 Subject: [PATCH] Suggested changes --- .../src/rules/helpers/JSXAttributes.ts | 3 +++ ...rContent-replace-noBackground-colorVariant.test.ts | 10 ++++++++++ ...drawerContent-replace-noBackground-colorVariant.ts | 11 +---------- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/JSXAttributes.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/JSXAttributes.ts index ea4fa8812..bf81fd33c 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/helpers/JSXAttributes.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/helpers/JSXAttributes.ts @@ -95,4 +95,7 @@ export function getAttributeValue( if (isExpressionContainer && node.expression.type === "MemberExpression") { return getMemberExpression(node.expression); } + if (isExpressionContainer && node.expression.type === "Literal") { + return node.expression.value; + } } diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.test.ts index 560ab8eb0..d69cd8776 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.test.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.test.ts @@ -33,6 +33,16 @@ ruleTester.run("drawerContent-replace-noBackground-colorVariant", rule, { }, ], }, + { + code: `import { DrawerContent } from '@patternfly/react-core'; `, + output: `import { DrawerContent } from '@patternfly/react-core'; `, + errors: [ + { + message: `The "no-background" value of the \`colorVariant\` prop on DrawerContent has been removed.`, + type: "JSXOpeningElement", + }, + ], + }, { code: `import { DrawerContent } from '@patternfly/react-core'; const color = "no-background"; `, output: `import { DrawerContent } from '@patternfly/react-core'; const color = "no-background"; `, diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.ts index cffe07db8..7cca10765 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/drawerContentReplaceNoBackgroundColorVariant/drawerContent-replace-noBackground-colorVariant.ts @@ -1,5 +1,5 @@ import { Rule } from "eslint"; -import { JSXOpeningElement, MemberExpression } from "estree-jsx"; +import { JSXOpeningElement } from "estree-jsx"; import { getFromPackage, getAttribute, getAttributeValue } from "../../helpers"; // https://github.com/patternfly/patternfly-react/pull/10211 @@ -78,15 +78,6 @@ module.exports = { ) ); } - - if (!hasNoBackgroundValue && !hasPatternFlyEnum) { - fixes.push( - fixer.replaceText( - colorVariantProp, - `colorVariant="${colorVariantValue}"` - ) - ); - } return fixes; }, });