Skip to content

Commit

Permalink
feat(InvalidObject): rename props (#714)
Browse files Browse the repository at this point in the history
* docs: fix multi-content-card rule description PR link

* feat(CG - InvalidObject): rename props
  • Loading branch information
adamviktora authored Jul 26, 2024
1 parent 0b39206 commit 7ca12d9
Show file tree
Hide file tree
Showing 5 changed files with 152 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### component-groups-invalidObject-rename-props [(react-component-groups/#145)](https://github.com/patternfly/react-component-groups/pull/145)

In react-component-groups, we've renamed InvalidObject's props `invalidObjectTitleText` to `titleText` and `invalidObjectBodyText` to `bodyText`.

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```

Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
const ruleTester = require("../../ruletester");
import * as rule from "./component-groups-invalidObject-rename-props";

const renameMap = {
invalidObjectTitleText: "titleText",
invalidObjectBodyText: "bodyText",
};

const errors = Object.entries(renameMap).map(([oldName, newName]) => ({
message: `The ${oldName} prop for InvalidObject has been renamed to ${newName}.`,
type: "JSXOpeningElement",
}));

ruleTester.run("component-groups-invalidObject-rename-props", rule, {
valid: [
{
code: `<InvalidObject invalidObjectTitleText="" />`,
},
{
code: `<InvalidObject invalidObjectBodyText="" />`,
},
{
code: `import { InvalidObject } from '@patternfly/react-component-groups'; <InvalidObject someOtherProp />`,
},
],
invalid: [
{
code: `import { InvalidObject } from '@patternfly/react-component-groups';
<InvalidObject
invalidObjectTitleText="Sample title text"
invalidObjectBodyText="Sample body text"
/>`,
output: `import { InvalidObject } from '@patternfly/react-component-groups';
<InvalidObject
titleText="Sample title text"
bodyText="Sample body text"
/>`,
errors,
},
{
code: `import InvalidObject from '@patternfly/react-component-groups/dist/cjs/InvalidObject/index';
<InvalidObject
invalidObjectTitleText="Sample title text"
invalidObjectBodyText="Sample body text"
/>`,
output: `import InvalidObject from '@patternfly/react-component-groups/dist/cjs/InvalidObject/index';
<InvalidObject
titleText="Sample title text"
bodyText="Sample body text"
/>`,
errors,
},
{
code: `import InvalidObject from '@patternfly/react-component-groups/dist/esm/InvalidObject/index';
<InvalidObject
invalidObjectTitleText="Sample title text"
invalidObjectBodyText="Sample body text"
/>`,
output: `import InvalidObject from '@patternfly/react-component-groups/dist/esm/InvalidObject/index';
<InvalidObject
titleText="Sample title text"
bodyText="Sample body text"
/>`,
errors,
},
{
code: `import InvalidObject from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
<InvalidObject
invalidObjectTitleText="Sample title text"
invalidObjectBodyText="Sample body text"
/>`,
output: `import InvalidObject from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
<InvalidObject
titleText="Sample title text"
bodyText="Sample body text"
/>`,
errors,
},
{
code: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
<InvObj
invalidObjectTitleText="Sample title text"
invalidObjectBodyText="Sample body text"
/>`,
output: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
<InvObj
titleText="Sample title text"
bodyText="Sample body text"
/>`,
errors,
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { renameProps } from "../../helpers";
import { Renames } from "../../helpers/renameSinglePropOnNode";

// https://github.com/patternfly/react-component-groups/pull/145

const formatMessage = (oldPropName: string, newPropName: string) =>
`The ${oldPropName} prop for InvalidObject has been renamed to ${newPropName}.`;

const renames: Renames = {
InvalidObject: {
invalidObjectTitleText: {
newName: "titleText",
message: formatMessage("invalidObjectTitleText", "titleText"),
},
invalidObjectBodyText: {
newName: "bodyText",
message: formatMessage("invalidObjectBodyText", "bodyText"),
},
},
};

module.exports = {
meta: { fixable: "code" },
create: renameProps(renames, "@patternfly/react-component-groups"),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { InvalidObject } from "@patternfly/react-component-groups";

export const ComponentGroupsInvalidObjectRenamePropsInput = () => (
<InvalidObject
invalidObjectTitleText="Sample title"
invalidObjectBodyText="Sample description"
/>
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { InvalidObject } from "@patternfly/react-component-groups";

export const ComponentGroupsInvalidObjectRenamePropsInput = () => (
<InvalidObject
titleText="Sample title"
bodyText="Sample description"
/>
);

0 comments on commit 7ca12d9

Please sign in to comment.