diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.test.ts index 6316b72d..dc86443a 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.test.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.test.ts @@ -183,6 +183,12 @@ ruleTester.run("text-replace-with-content", rule, { jsxClosingElementError, ], }, + // dist import path (Text, TextContent, TextList and TextListItem are all under "Text") + { + code: `import { Text } from '@patternfly/react-core/dist/dynamic/components/Text';`, + output: `import { Content } from "@patternfly/react-core/dist/dynamic/components/Content";`, + errors: [importDeclarationError], + }, ], }); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.ts index d97ade69..afe96af9 100644 --- a/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.ts +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.ts @@ -71,11 +71,32 @@ module.exports = { const specifierName = specifierToReplace.imported.name; const newText = getNewText(specifierName); + const importPath = node.source.value?.toString(); + + if (!importPath) { + return; + } + context.report({ node, message: errorMessage, fix(fixer) { - return fixer.replaceText(specifierToReplace, newText); + const specifierFix = fixer.replaceText( + specifierToReplace, + newText + ); + + if (!importPath.includes("Text")) { + return specifierFix; + } + + return [ + specifierFix, + fixer.replaceText( + node.source, + `"${importPath.replace("Text", "Content")}"` + ), + ]; }, }); }