Skip to content

Commit

Permalink
account for default import
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcfaul committed Sep 26, 2024
1 parent 68e55d7 commit 2fa1ae7
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export function pfPackageMatches(
parts[1] +
"(/dist/(esm|js|dynamic))?" +
(parts[2] ? "/" + parts[2] : "") +
(parts[1] === "react-component-groups"
(parts[1] === "react-component-groups" || parts[1] === "react-user-feedback"
? `(/.*)?$`
: `(/(components|helpers${
parts[1] === "react-icons" ? "|icons" : ""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@ ruleTester.run("user-feedback-warn-changes", rule, {
},
],
},
// {
// code: `import myDefaultModal from '@patternfly/react-user-feedback';`,
// output: `import myDefaultModal from '@patternfly/react-user-feedback';`,
// errors: [
// {
// message: `FeedbackModal no longer internally references a scss stylesheet. You may have to import "Feedback.css" located in the dist "@patternfly/react-user-feedback/dist/esm/Feedback/Feedback.css" to maintain styling on FeedbackModal.`,
// type: "ImportDeclaration",
// },
// ],
// },
{
code: `import myDefaultModal from '@patternfly/react-user-feedback/dist/esm/Feedback/FeedbackModal';`,
output: `import myDefaultModal from '@patternfly/react-user-feedback/dist/esm/Feedback/FeedbackModal';`,
errors: [
{
message: `FeedbackModal no longer internally references a scss stylesheet. You may have to import "Feedback.css" located in the dist "@patternfly/react-user-feedback/dist/esm/Feedback/Feedback.css" to maintain styling on FeedbackModal.`,
type: "ImportDeclaration",
},
],
},
],
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,15 @@ module.exports = {
create: function (context: Rule.RuleContext) {
const imports = getAllImportsFromPackage(context, "@patternfly/react-user-feedback", ["FeedbackModal"]);

const namedImports = imports.filter(
(imp) => imp.type === "ImportSpecifier"
) as ImportSpecifier[];

const feedbackModalImport = namedImports.find(
(specifier: { imported: { name: string } }) =>
specifier.imported.name === "FeedbackModal"
);

return !feedbackModalImport
return !imports.length
? {}
: {
ImportDeclaration(node: ImportDeclaration) {
if (
node.specifiers.find(
(specifier) =>
specifier.type === "ImportSpecifier" &&
specifier.imported.name === getComponentImportName(feedbackModalImport, ["FeedbackModal"])
(specifier.type === "ImportSpecifier" || specifier.type === "ImportDefaultSpecifier")
&& getComponentImportName(specifier, ["FeedbackModal"]) === "FeedbackModal"
)
) {
context.report({
Expand Down

0 comments on commit 2fa1ae7

Please sign in to comment.