Skip to content

Commit 0af1541

Browse files
feat(JumpLinks): warned about href and markup/type updates (#575)
* feat(JumpLinks): warned about href and markup/type updates * Separated href rule so it will flag as an error * Added typing to PageSection rules * Updated typing in markup warn rule
1 parent e90502b commit 0af1541

13 files changed

+186
-36
lines changed

packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export const warningRules = [
1616
"emptyState-warn-change-structure",
1717
"formControls-updated-markup",
1818
"horizontalSubnav-warn-ariaLabel",
19+
"jumpLinksItem-warn-markup-change",
1920
"label-warn-truncated-default",
2021
"nav-warn-flyouts-now-inline",
2122
"overflowMenu-warn-updated-dropdownItem",
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### jumpLinksItem-href-required [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027)
2+
3+
The `href` prop on JumpLinksItem is now required.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
const ruleTester = require("../../ruletester");
2+
import * as rule from "./jumpLinksItem-href-required";
3+
4+
ruleTester.run("jumpLinksItem-href-required", rule, {
5+
valid: [
6+
{
7+
code: `import { JumpLinksItem } from 'someOtherPackage'; <JumpLinksItem />`,
8+
},
9+
{
10+
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href="someURL" />`,
11+
},
12+
],
13+
invalid: [
14+
{
15+
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`,
16+
output: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem />`,
17+
errors: [
18+
{
19+
message: `The \`href\` prop on JumpLinksItem is now required.`,
20+
type: "JSXOpeningElement",
21+
},
22+
],
23+
},
24+
{
25+
code: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href />`,
26+
output: `import { JumpLinksItem } from '@patternfly/react-core'; <JumpLinksItem href />`,
27+
errors: [
28+
{
29+
message: `The \`href\` prop on JumpLinksItem is now required.`,
30+
type: "JSXOpeningElement",
31+
},
32+
],
33+
},
34+
],
35+
});
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { getFromPackage } from "../../helpers";
2+
import { Rule } from "eslint";
3+
import { JSXOpeningElement, JSXAttribute } from "estree-jsx";
4+
5+
// https://github.com/patternfly/patternfly-react/pull/10027
6+
module.exports = {
7+
meta: {},
8+
create: function (context: Rule.RuleContext) {
9+
const { imports } = getFromPackage(context, "@patternfly/react-core");
10+
11+
const jumpLinksItemImport = imports.find(
12+
(specifier) => specifier.imported.name === "JumpLinksItem"
13+
);
14+
15+
return !jumpLinksItemImport
16+
? {}
17+
: {
18+
JSXOpeningElement(node: JSXOpeningElement) {
19+
if (
20+
node.name.type === "JSXIdentifier" &&
21+
jumpLinksItemImport.local.name === node.name.name
22+
) {
23+
const hrefAttribute = node.attributes.find(
24+
(attribute) =>
25+
attribute.type === "JSXAttribute" &&
26+
attribute.name.name === "href"
27+
);
28+
29+
if (!hrefAttribute || !(hrefAttribute as JSXAttribute).value) {
30+
context.report({
31+
node,
32+
message: "The `href` prop on JumpLinksItem is now required.",
33+
});
34+
}
35+
}
36+
},
37+
};
38+
},
39+
};
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { JumpLinksItem } from "@patternfly/react-core";
2+
3+
export const JumpLinksItemWarnMarkupChangeInput = () => (
4+
<>
5+
<JumpLinksItem />
6+
<JumpLinksItem href />
7+
</>
8+
);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import { JumpLinksItem } from "@patternfly/react-core";
2+
3+
export const JumpLinksItemWarnMarkupChangeInput = () => (
4+
<>
5+
<JumpLinksItem />
6+
<JumpLinksItem href />
7+
</>
8+
);
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
### jumpLinksItem-warn-markup-change [(#10027)](https://github.com/patternfly/patternfly-react/pull/10027)
2+
3+
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>`).
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
const ruleTester = require("../../ruletester");
2+
import * as rule from "./jumpLinksItem-warn-markup-change";
3+
4+
ruleTester.run("jumpLinksItem-warn-markup-change", rule, {
5+
valid: [
6+
{
7+
code: `import { JumpLinksItem } from '@someOtherPackage';`,
8+
},
9+
],
10+
invalid: [
11+
{
12+
code: `import { JumpLinksItem } from '@patternfly/react-core';`,
13+
output: `import { JumpLinksItem } from '@patternfly/react-core';`,
14+
errors: [
15+
{
16+
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>\`).`,
17+
type: "ImportDeclaration",
18+
},
19+
],
20+
},
21+
],
22+
});
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { getFromPackage } from "../../helpers";
2+
import { Rule } from "eslint";
3+
import { ImportDeclaration, ImportSpecifier } from "estree-jsx";
4+
5+
// https://github.com/patternfly/patternfly-react/pull/10027
6+
module.exports = {
7+
meta: {},
8+
create: function (context: Rule.RuleContext) {
9+
const { imports } = getFromPackage(context, "@patternfly/react-core");
10+
11+
const jumpLinksItemImport = imports.find(
12+
(specifier) => specifier.imported.name === "JumpLinksItem"
13+
);
14+
15+
return !jumpLinksItemImport
16+
? {}
17+
: {
18+
ImportDeclaration(node: ImportDeclaration) {
19+
if (
20+
node.specifiers.find(
21+
(specifier) =>
22+
specifier.type === "ImportSpecifier" &&
23+
specifier.imported.name === jumpLinksItemImport.imported.name
24+
)
25+
) {
26+
context.report({
27+
node,
28+
message:
29+
"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>`).",
30+
});
31+
}
32+
},
33+
};
34+
},
35+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
import { JumpLinksItem } from "@patternfly/react-core";

0 commit comments

Comments
 (0)