Skip to content

Commit 564e836

Browse files
authored
fix(TextReplaceWithContent): update dist import path (#797)
* fix(TextReplaceWithContent): update dist import path * fix: remove type casting
1 parent 9b83bc7 commit 564e836

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,12 @@ ruleTester.run("text-replace-with-content", rule, {
183183
jsxClosingElementError,
184184
],
185185
},
186+
// dist import path (Text, TextContent, TextList and TextListItem are all under "Text")
187+
{
188+
code: `import { Text } from '@patternfly/react-core/dist/dynamic/components/Text';`,
189+
output: `import { Content } from "@patternfly/react-core/dist/dynamic/components/Content";`,
190+
errors: [importDeclarationError],
191+
},
186192
],
187193
});
188194

packages/eslint-plugin-pf-codemods/src/rules/v6/textReplaceWithContent/text-replace-with-content.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,32 @@ module.exports = {
7171
const specifierName = specifierToReplace.imported.name;
7272
const newText = getNewText(specifierName);
7373

74+
const importPath = node.source.value?.toString();
75+
76+
if (!importPath) {
77+
return;
78+
}
79+
7480
context.report({
7581
node,
7682
message: errorMessage,
7783
fix(fixer) {
78-
return fixer.replaceText(specifierToReplace, newText);
84+
const specifierFix = fixer.replaceText(
85+
specifierToReplace,
86+
newText
87+
);
88+
89+
if (!importPath.includes("Text")) {
90+
return specifierFix;
91+
}
92+
93+
return [
94+
specifierFix,
95+
fixer.replaceText(
96+
node.source,
97+
`"${importPath.replace("Text", "Content")}"`
98+
),
99+
];
79100
},
80101
});
81102
}

0 commit comments

Comments
 (0)