Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
account for default import
Browse files Browse the repository at this point in the history
kmcfaul committed Sep 26, 2024
1 parent 8c6f315 commit b2757c8
Showing 3 changed files with 14 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ export function pfPackageMatches(
parts[1] +
"(/dist/(esm|js|dynamic))?" +
(parts[2] ? "/" + parts[2] : "") +
(["react-component-groups", "react-tokens"].includes(parts[1])
(["react-component-groups", "react-tokens", "react-user-feedback"].includes(parts[1])
? `(/.*)?$`
: `(/(components|helpers${
parts[1] === "react-icons" ? "|icons" : ""
Original file line number Diff line number Diff line change
@@ -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
@@ -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({

0 comments on commit b2757c8

Please sign in to comment.