Skip to content

Commit e90502b

Browse files
chore(Page): updated props @thatblindgeye (#568)
* chore(Page): updated props * Added rules for PageSection changes
1 parent 1ded4ca commit e90502b

22 files changed

+333
-1
lines changed

generators/src/write-rule.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ export async function genericRule({
3131
// https://github.com/patternfly/patternfly-react/pull/${referencePR}
3232
module.exports = {
3333
meta: { fixable: 'code' },
34-
create: function(context: { report: (arg0: { node: any; message: string; fix(fixer: any): any; }) => void; }) {
34+
create: function(context: { report: (arg0: { node: any; message: string; fix?(fixer: any): any; }) => void; }) {
3535
const {imports, exports} = getFromPackage(context, '@patternfly/react-core')
3636
3737
const componentImports = imports.filter((specifier: { imported: { name: string; }; }) => specifier.imported.name === '${componentName}');

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export const warningRules = [
1919
"label-warn-truncated-default",
2020
"nav-warn-flyouts-now-inline",
2121
"overflowMenu-warn-updated-dropdownItem",
22+
"pageSection-warn-variantClasses-applied",
2223
"popover-warn-appendTo-default",
2324
"react-dropzone-warn-upgrade",
2425
"table-warn-actionsColumn",
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### pageHeaderToolsItem-remove-isSelected-prop [(#9774)](https://github.com/patternfly/patternfly-react/pull/9774)
2+
3+
The `isSelected` prop has been removed from PageHeaderToolsItem.
4+
5+
#### Examples
6+
7+
In:
8+
9+
```jsx
10+
%inputExample%
11+
```
12+
13+
Out:
14+
15+
```jsx
16+
%outputExample%
17+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
const ruleTester = require("../../ruletester");
2+
import * as rule from "./pageHeaderToolsItem-remove-isSelected-prop";
3+
4+
ruleTester.run("pageHeaderToolsItem-remove-isSelected-prop", rule, {
5+
valid: [
6+
{
7+
code: `<PageHeaderToolsItem isSelected />`,
8+
},
9+
{
10+
code: `import { PageHeaderToolsItem } from '@patternfly/react-core/deprecated'; <PageHeaderToolsItem someOtherProp />`,
11+
},
12+
],
13+
invalid: [
14+
{
15+
code: `import { PageHeaderToolsItem } from '@patternfly/react-core/deprecated'; <PageHeaderToolsItem isSelected />`,
16+
output: `import { PageHeaderToolsItem } from '@patternfly/react-core/deprecated'; <PageHeaderToolsItem />`,
17+
errors: [
18+
{
19+
message: `The \`isSelected\` prop has been removed from PageHeaderToolsItem.`,
20+
type: "JSXOpeningElement",
21+
},
22+
],
23+
},
24+
],
25+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { renameProps } from "../../helpers";
2+
3+
// https://github.com/patternfly/patternfly-react/pull/9774
4+
module.exports = {
5+
meta: { fixable: "code" },
6+
create: renameProps(
7+
{
8+
PageHeaderToolsItem: {
9+
isSelected: {
10+
newName: "",
11+
message:
12+
"The `isSelected` prop has been removed from PageHeaderToolsItem.",
13+
},
14+
},
15+
},
16+
"@patternfly/react-core/deprecated"
17+
),
18+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PageHeaderToolsItem } from "@patternfly/react-core/deprecated";
2+
3+
export const PageHeaderToolsItemRemoveIsSelectedPropInput = () => (
4+
<PageHeaderToolsItem isSelected />
5+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { PageHeaderToolsItem } from "@patternfly/react-core/deprecated";
2+
3+
export const PageHeaderToolsItemRemoveIsSelectedPropInput = () => (
4+
<PageHeaderToolsItem />
5+
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### pageSection-update-variant-values [(#9774)](https://github.com/patternfly/patternfly-react/pull/9774) [(#9848)](https://github.com/patternfly/patternfly-react/pull/9848)
2+
3+
The `variant` prop for PageSection now only accepts a value of "default" or "secondary". Running the fix for this rule will remove the prop so it uses the default value of "default".
4+
5+
#### Examples
6+
7+
In:
8+
9+
```jsx
10+
%inputExample%
11+
```
12+
13+
Out:
14+
15+
```jsx
16+
%outputExample%
17+
```
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
const ruleTester = require("../../ruletester");
2+
import * as rule from "./pageSection-update-variant-values";
3+
4+
ruleTester.run("pageSection-update-variant-values", rule, {
5+
valid: [
6+
{
7+
code: `<PageSection variant="dark" />`,
8+
},
9+
{
10+
code: `import { PageSection } from '@patternfly/react-core'; <PageSection someOtherProp />`,
11+
},
12+
{
13+
code: `import { PageSection } from '@patternfly/react-core'; <PageSection variant="default" />`,
14+
},
15+
{
16+
code: `import { PageSection } from '@patternfly/react-core'; <PageSection variant="secondary" />`,
17+
},
18+
],
19+
invalid: [
20+
{
21+
code: `import { PageSection } from '@patternfly/react-core'; <PageSection variant="dark" />`,
22+
output: `import { PageSection } from '@patternfly/react-core'; <PageSection />`,
23+
errors: [
24+
{
25+
message: `The \`variant\` prop for PageSection now only accepts a value of "default" or "secondary". Running the fix for this rule will remove the prop so it uses the default value of "default".`,
26+
type: "JSXOpeningElement",
27+
},
28+
],
29+
},
30+
],
31+
});
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { getFromPackage } from "../../helpers";
2+
3+
// https://github.com/patternfly/patternfly-react/pull/9774
4+
// https://github.com/patternfly/patternfly-react/pull/9848
5+
module.exports = {
6+
meta: { fixable: "code" },
7+
create: function (context: {
8+
report: (arg0: {
9+
node: any;
10+
message: string;
11+
fix(fixer: any): any;
12+
}) => void;
13+
}) {
14+
const { imports } = getFromPackage(context, "@patternfly/react-core");
15+
16+
const componentImports = imports.filter(
17+
(specifier: { imported: { name: string } }) =>
18+
specifier.imported.name === "PageSection"
19+
);
20+
21+
return !componentImports.length
22+
? {}
23+
: {
24+
JSXOpeningElement(node: { name: { name: any }; attributes: any[] }) {
25+
if (
26+
componentImports
27+
.map((imp: { local: { name: any } }) => imp.local.name)
28+
.includes(node.name.name)
29+
) {
30+
const attribute = node.attributes.find(
31+
(attr: { name: { name: string } }) =>
32+
attr.name?.name === "variant"
33+
);
34+
35+
if (
36+
attribute &&
37+
!["default", "secondary"].includes(attribute.value.value)
38+
) {
39+
context.report({
40+
node,
41+
message:
42+
'The `variant` prop for PageSection now only accepts a value of "default" or "secondary". Running the fix for this rule will remove the prop so it uses the default value of "default".',
43+
fix(fixer: {
44+
replaceText: (arg0: any, arg1: string) => any;
45+
}) {
46+
return fixer.replaceText(attribute, "");
47+
},
48+
});
49+
}
50+
}
51+
},
52+
};
53+
},
54+
};

0 commit comments

Comments
 (0)