Skip to content

Commit

Permalink
feat(Menu): updated markup for MenuItemAction (#590)
Browse files Browse the repository at this point in the history
* feat(Menu): updated markup for MenuItemAction

* Added rules to beta array
  • Loading branch information
thatblindgeye authored Feb 28, 2024
1 parent 3d0cbb1 commit 2fa045b
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 2 deletions.
6 changes: 5 additions & 1 deletion packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// if you want your rule to only run when explicitly called for using the --only flag, add the rule name to the below array
export const betaRuleNames: string[] = [];
export const betaRuleNames: string[] = [
"menuItemAction-warn-update-markup",
"menuToggle-warn-iconOnly-toggle",
];

// if you want a rule to have a severity that defaults to warning rather than error, add the rule name to the below array
export const warningRules = [
Expand All @@ -21,6 +24,7 @@ export const warningRules = [
"horizontalSubnav-warn-ariaLabel",
"jumpLinksItem-warn-markup-change",
"label-warn-truncated-default",
"menuItemAction-warn-update-markup",
"menuToggle-warn-iconOnly-toggle",
"nav-warn-flyouts-now-inline",
"notificationBadge-warn-markup-change",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { getFromPackage } from "../../helpers";
import { Rule } from "eslint";
import { ImportDeclaration, ImportSpecifier } from "estree-jsx";
import { ImportDeclaration } from "estree-jsx";

// https://github.com/patternfly/patternfly-react/pull/10027
module.exports = {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### menuItemAction-warn-update-markup [(#10089)](https://github.com/patternfly/patternfly-react/pull/10089)

The markup for MenuItemAction has been updated. It now uses our Button component internally, has a wrapper around the action button, and no longer renders an icon wrapper inside the action button.
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const ruleTester = require("../../ruletester");
import * as rule from "./menuItemAction-warn-update-markup";

ruleTester.run("menuItemAction-warn-update-markup", rule, {
valid: [
{
code: `import { MenuItemAction } from '@someOtherPackage';`,
},
],
invalid: [
{
code: `import { MenuItemAction } from '@patternfly/react-core';`,
output: `import { MenuItemAction } from '@patternfly/react-core';`,
errors: [
{
message: `The markup for MenuItemAction has been updated. It now uses our Button component internally, has a wrapper around the action button, and no longer renders an icon wrapper inside the action button.`,
type: "ImportDeclaration",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { getFromPackage } from "../../helpers";
import { Rule } from "eslint";
import { ImportDeclaration } from "estree-jsx";

// https://github.com/patternfly/patternfly-react/pull/10089
module.exports = {
meta: {},
create: function (context: Rule.RuleContext) {
const { imports } = getFromPackage(context, "@patternfly/react-core");

const menuItemActionImport = imports.find(
(specifier) => specifier.imported.name === "MenuItemAction"
);

return !menuItemActionImport
? {}
: {
ImportDeclaration(node: ImportDeclaration) {
if (
node.specifiers.find(
(specifier) =>
specifier.type === "ImportSpecifier" &&
specifier.imported.name === menuItemActionImport.imported.name
)
) {
context.report({
node,
message:
"The markup for MenuItemAction has been updated. It now uses our Button component internally, has a wrapper around the action button, and no longer renders an icon wrapper inside the action button.",
});
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { MenuItemAction } from "@patternfly/react-core";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
import { MenuItemAction } from "@patternfly/react-core";

0 comments on commit 2fa045b

Please sign in to comment.