Skip to content

Commit 9aaabca

Browse files
authored
feat(CG - NotAuthorized): rename props (#715)
1 parent b9f4286 commit 9aaabca

File tree

5 files changed

+145
-0
lines changed

5 files changed

+145
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
### component-groups-notAuthorized-rename-props [(react-component-groups/#145)](https://github.com/patternfly/react-component-groups/pull/145)
2+
3+
In react-component-groups, we've renamed NotAuthorized's props `description` to `bodyText` and `title` to `titleText`.
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,93 @@
1+
const ruleTester = require("../../ruletester");
2+
import * as rule from "./component-groups-notAuthorized-rename-props";
3+
4+
const renameMap = {
5+
description: "bodyText",
6+
title: "titleText",
7+
};
8+
9+
const errors = Object.entries(renameMap).map(([oldName, newName]) => ({
10+
message: `The ${oldName} prop for NotAuthorized has been renamed to ${newName}.`,
11+
type: "JSXOpeningElement",
12+
}));
13+
14+
ruleTester.run("component-groups-notAuthorized-rename-props", rule, {
15+
valid: [
16+
{
17+
code: `<NotAuthorized description="" />`,
18+
},
19+
{
20+
code: `<NotAuthorized title="" />`,
21+
},
22+
{
23+
code: `import { NotAuthorized } from '@patternfly/react-component-groups'; <NotAuthorized someOtherProp />`,
24+
},
25+
],
26+
invalid: [
27+
{
28+
code: `import { NotAuthorized } from '@patternfly/react-component-groups';
29+
<NotAuthorized
30+
description="Description text"
31+
title="Title text"
32+
/>`,
33+
output: `import { NotAuthorized } from '@patternfly/react-component-groups';
34+
<NotAuthorized
35+
bodyText="Description text"
36+
titleText="Title text"
37+
/>`,
38+
errors,
39+
},
40+
{
41+
code: `import NotAuthorized from '@patternfly/react-component-groups/dist/cjs/NotAuthorized/index';
42+
<NotAuthorized
43+
description="Description text"
44+
title="Title text"
45+
/>`,
46+
output: `import NotAuthorized from '@patternfly/react-component-groups/dist/cjs/NotAuthorized/index';
47+
<NotAuthorized
48+
bodyText="Description text"
49+
titleText="Title text"
50+
/>`,
51+
errors,
52+
},
53+
{
54+
code: `import NotAuthorized from '@patternfly/react-component-groups/dist/esm/NotAuthorized/index';
55+
<NotAuthorized
56+
description="Description text"
57+
title="Title text"
58+
/>`,
59+
output: `import NotAuthorized from '@patternfly/react-component-groups/dist/esm/NotAuthorized/index';
60+
<NotAuthorized
61+
bodyText="Description text"
62+
titleText="Title text"
63+
/>`,
64+
errors,
65+
},
66+
{
67+
code: `import NotAuthorized from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
68+
<NotAuthorized
69+
description="Description text"
70+
title="Title text"
71+
/>`,
72+
output: `import NotAuthorized from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
73+
<NotAuthorized
74+
bodyText="Description text"
75+
titleText="Title text"
76+
/>`,
77+
errors,
78+
},
79+
{
80+
code: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
81+
<NotAuth
82+
description="Description text"
83+
title="Title text"
84+
/>`,
85+
output: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
86+
<NotAuth
87+
bodyText="Description text"
88+
titleText="Title text"
89+
/>`,
90+
errors,
91+
},
92+
],
93+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { renameProps } from "../../helpers";
2+
import { Renames } from "../../helpers/renameSinglePropOnNode";
3+
4+
// https://github.com/patternfly/react-component-groups/pull/145
5+
6+
const formatMessage = (oldPropName: string, newPropName: string) =>
7+
`The ${oldPropName} prop for NotAuthorized has been renamed to ${newPropName}.`;
8+
9+
const renames: Renames = {
10+
NotAuthorized: {
11+
description: {
12+
newName: "bodyText",
13+
message: formatMessage("description", "bodyText"),
14+
},
15+
title: {
16+
newName: "titleText",
17+
message: formatMessage("title", "titleText"),
18+
},
19+
},
20+
};
21+
22+
module.exports = {
23+
meta: { fixable: "code" },
24+
create: renameProps(renames, "@patternfly/react-component-groups"),
25+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NotAuthorized } from "@patternfly/react-component-groups";
2+
3+
export const ComponentGroupsNotAuthorizedRenamePropsInput = () => (
4+
<NotAuthorized description="Description text" title="Title text" />
5+
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import { NotAuthorized } from "@patternfly/react-component-groups";
2+
3+
export const ComponentGroupsNotAuthorizedRenamePropsInput = () => (
4+
<NotAuthorized bodyText="Description text" titleText="Title text" />
5+
);

0 commit comments

Comments
 (0)