Skip to content

Commit

Permalink
feat(codemod): rename ContentHeader to PageHeader
Browse files Browse the repository at this point in the history
  • Loading branch information
adamviktora committed Sep 23, 2024
1 parent 9d9cd73 commit e12f567
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
### component-groups-contentHeader-rename-to-pageHeader [(react-component-groups/#313)](https://github.com/patternfly/react-component-groups/pull/313)

In react-component-groups, we've renamed ContentHeader component to PageHeader

#### Examples

In:

```jsx
%inputExample%
```

Out:

```jsx
%outputExample%
```

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

const errors = [
{
message: `ContentHeader has been renamed to PageHeader.`,
type: "JSXOpeningElement",
},
];

ruleTester.run("component-groups-contentHeader-rename-to-pageHeader", rule, {
valid: [
// missing import
{
code: `<ContentHeader />`,
},
// import from wrong package
{
code: `import { ContentHeader } from '@patternfly/react-core'; <ContentHeader />`,
},
],
invalid: [
{
code: `import { ContentHeader } from '@patternfly/react-component-groups'; <ContentHeader />`,
output: `import { PageHeader } from '@patternfly/react-component-groups'; <PageHeader data-codemods />`,
errors,
},
// named import with alias
{
code: `import { ContentHeader as Header } from '@patternfly/react-component-groups'; <Header />`,
output: `import { PageHeader as Header } from '@patternfly/react-component-groups'; <Header />`,
errors,
},
// default imports
{
code: `import ContentHeader from '@patternfly/react-component-groups/dist/cjs/ContentHeader/index'; <ContentHeader />`,
output: `import PageHeader from '@patternfly/react-component-groups/dist/cjs/PageHeader/index'; <PageHeader data-codemods />`,
errors,
},
{
code: `import ContentHeader from '@patternfly/react-component-groups/dist/esm/ContentHeader/index'; <ContentHeader />`,
output: `import PageHeader from '@patternfly/react-component-groups/dist/esm/PageHeader/index'; <PageHeader data-codemods />`,
errors,
},
{
code: `import ContentHeader from '@patternfly/react-component-groups/dist/dynamic/ContentHeader'; <ContentHeader />`,
output: `import PageHeader from '@patternfly/react-component-groups/dist/dynamic/PageHeader'; <PageHeader data-codemods />`,
errors,
},
// default import with name not matching the component name
{
code: `import Header from '@patternfly/react-component-groups/dist/dynamic/ContentHeader'; <Header />`,
output: `import Header from '@patternfly/react-component-groups/dist/dynamic/PageHeader'; <Header />`,
errors,
},
],
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { renameComponent } from "../../helpers/renameComponent";

// https://github.com/patternfly/react-component-groups/pull/313
module.exports = {
meta: { fixable: "code" },
create: renameComponent(
{
ContentHeader: "PageHeader",
},
"@patternfly/react-component-groups"
),
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { ContentHeader } from "@patternfly/react-component-groups";

export const ComponentGroupsContentHeaderRenameToPageHeaderInput = () => (
<ContentHeader />
);
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { PageHeader } from "@patternfly/react-component-groups";

export const ComponentGroupsContentHeaderRenameToPageHeaderInput = () => (
<PageHeader data-codemods />
);

0 comments on commit e12f567

Please sign in to comment.