Skip to content

Commit

Permalink
Separated href rule so it will flag as an error
Browse files Browse the repository at this point in the history
  • Loading branch information
thatblindgeye committed Feb 26, 2024
1 parent e1c8083 commit c5e7364
Show file tree
Hide file tree
Showing 14 changed files with 158 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export const warningRules = [
"emptyState-warn-change-structure",
"formControls-updated-markup",
"horizontalSubnav-warn-ariaLabel",
"jumpLinksItem-warn-prop-markup-updates",
"jumpLinksItem-warn-markup-change",
"label-warn-truncated-default",
"nav-warn-flyouts-now-inline",
"overflowMenu-warn-updated-dropdownItem",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### jumpLinksItem-href-required [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027)

The `href` prop on JumpLinksItem is now required.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
const ruleTester = require("../../ruletester");
import * as rule from "./jumpLinksItem-href-required";

ruleTester.run("jumpLinksItem-href-required", rule, {
valid: [
{
code: `import { JumpLinksItem } from 'someOtherPackage'; <JumpLinksItem />`,
},
{
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href="someURL" />`,
},
],
invalid: [
{
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`,
output: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`,
errors: [
{
message: `The \`href\` prop on JumpLinksItem is now required.`,
type: "JSXOpeningElement",
},
],
},
{
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href />`,
output: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href />`,
errors: [
{
message: `The \`href\` prop on JumpLinksItem is now required.`,
type: "JSXOpeningElement",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { getFromPackage } from "../../helpers";
import { Rule } from "eslint";
import { JSXOpeningElement, JSXAttribute } from "estree-jsx";

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

const jumpLinksItemImport = imports.find(
(specifier) => specifier.imported.name === "JumpLinksItem"
);

return !jumpLinksItemImport
? {}
: {
JSXOpeningElement(node: JSXOpeningElement) {
if (
node.name.type === "JSXIdentifier" &&
jumpLinksItemImport.local.name === node.name.name
) {
const hrefAttribute = node.attributes.find(
(attribute) =>
attribute.type === "JSXAttribute" &&
attribute.name.name === "href"
);

if (!hrefAttribute || !(hrefAttribute as JSXAttribute).value) {
context.report({
node,
message: "The `href` prop on JumpLinksItem is now required.",
});
}
}
},
};
},
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { JumpLinksItem } from "@patternfly/react-core";

export const JumpLinksItemWarnMarkupChangeInput = () => (
<>
<JumpLinksItem />
<JumpLinksItem href />
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { JumpLinksItem } from "@patternfly/react-core";

export const JumpLinksItemWarnMarkupChangeInput = () => (
<>
<JumpLinksItem />
<JumpLinksItem href />
</>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### jumpLinksItem-warn-markup-change [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027)

The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the `onClick` prop type has been updated to just `React.MouseEvent` (previously `React.MouseEvent<HTMLAnchorElement>`).
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const ruleTester = require("../../ruletester");
import * as rule from "./jumpLinksItem-warn-markup-change";

ruleTester.run("jumpLinksItem-warn-markup-change", rule, {
valid: [
{
code: `<JumpLinksItem />`,
},
{
code: `import { JumpLinksItem } from '@someOtherPackage';`,
},
],
invalid: [
{
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`,
output: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`,
errors: [
{
message: `The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the \`onClick\` prop type has been updated to just \`React.MouseEvent\` (previously \`React.MouseEvent<HTMLAnchorElement>\`).`,
type: "ImportDeclaration",
},
],
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { getFromPackage } from "../../helpers";
import { Rule } from "eslint";
import { ImportDeclaration, ImportSpecifier } from "estree-jsx";

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

const jumpLinksItemImport = imports.find(
(specifier: { imported: { name: string } }) =>
specifier.imported.name === "JumpLinksItem"
);

return !jumpLinksItemImport
? {}
: {
ImportDeclaration(node: ImportDeclaration) {
if (
node.specifiers.find(
(specifier) =>
(specifier as ImportSpecifier)?.imported.name ===
jumpLinksItemImport.imported.name
)
) {
context.report({
node,
message:
"The markup for JumpLinksItem has changed, as it now uses our Button component internally. Additionally, the `onClick` prop type has been updated to just `React.MouseEvent` (previously `React.MouseEvent<HTMLAnchorElement>`).",
});
}
},
};
},
};

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit c5e7364

Please sign in to comment.