Skip to content

Commit

Permalink
fix(TextReplaceWithContent): update dist import path (#797)
Browse files Browse the repository at this point in the history
* fix(TextReplaceWithContent): update dist import path

* fix: remove type casting
  • Loading branch information
adamviktora authored Jan 20, 2025
1 parent 9b83bc7 commit 564e836
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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],
},
],
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")}"`
),
];
},
});
}
Expand Down

0 comments on commit 564e836

Please sign in to comment.