Skip to content

Commit

Permalink
account for alias, default
Browse files Browse the repository at this point in the history
  • Loading branch information
kmcfaul committed Sep 24, 2024
1 parent c5385e7 commit 68e55d7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ ruleTester.run("user-feedback-warn-changes", rule, {
},
],
},
// Test that a warning only gets flagged once
{
code: `import { FeedbackModal } from '@patternfly/react-user-feedback';`,
output: `import { FeedbackModal } from '@patternfly/react-user-feedback';`,
code: `import { FeedbackModal as MyModal } from '@patternfly/react-user-feedback';`,
output: `import { FeedbackModal as MyModal } 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';`,
// 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",
// },
// ],
// },
],
});
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
import { getFromPackage } from "../../helpers";
import { getAllImportsFromPackage, getComponentImportName, getDefaultDeclarationString } from "../../helpers";
import { Rule } from "eslint";
import { ImportDeclaration } from "estree-jsx";
import { ImportDeclaration, ImportSpecifier } from "estree-jsx";

// https://github.com/patternfly/react-user-feedback/pull/76
module.exports = {
meta: {},
create: function (context: Rule.RuleContext) {
const { imports } = getFromPackage(context, "@patternfly/react-user-feedback");
const imports = getAllImportsFromPackage(context, "@patternfly/react-user-feedback", ["FeedbackModal"]);

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

const feedbackModalImport = namedImports.find(
(specifier: { imported: { name: string } }) =>
specifier.imported.name === "FeedbackModal"
);
Expand All @@ -21,9 +25,8 @@ module.exports = {
node.specifiers.find(
(specifier) =>
specifier.type === "ImportSpecifier" &&
specifier.imported.name ===
feedbackModalImport.imported.name
)
specifier.imported.name === getComponentImportName(feedbackModalImport, ["FeedbackModal"])
)
) {
context.report({
node,
Expand Down

0 comments on commit 68e55d7

Please sign in to comment.