From aa1d1521212c3e8ab67936ec0f361db3e5068c25 Mon Sep 17 00:00:00 2001
From: adamviktora <84135613+adamviktora@users.noreply.github.com>
Date: Tue, 24 Sep 2024 20:35:21 +0200
Subject: [PATCH] feat(component groups): rename various components (#776)
* feat(renameComponents helper): rename node when default import matches component name
* feat(dataCodemodsCleanup): include component-groups package
* feat(codemod): rename ContentHeader to PageHeader
* feat(codemod): rename InvalidObject to MissingPage
* feat(codemod): rename NotAuthorized to UnauthorizedAccess
---
.../src/rules/helpers/renameComponent.ts | 12 +-
...oups-contentHeader-rename-to-pageHeader.md | 18 +++
...contentHeader-rename-to-pageHeader.test.ts | 57 +++++++
...oups-contentHeader-rename-to-pageHeader.ts | 12 ++
...psContentHeaderRenameToPageHeaderInput.tsx | 5 +
...sContentHeaderRenameToPageHeaderOutput.tsx | 5 +
...-groups-invalidObject-rename-props.test.ts | 145 ++++++++++--------
...onent-groups-invalidObject-rename-props.ts | 31 ++--
...ups-invalidObject-rename-to-missingPage.md | 18 +++
...nvalidObject-rename-to-missingPage.test.ts | 57 +++++++
...ups-invalidObject-rename-to-missingPage.ts | 12 ++
...sInvalidObjectRenameToMissingPageInput.tsx | 4 +
...InvalidObjectRenameToMissingPageOutput.tsx | 4 +
...-groups-notAuthorized-rename-props.test.ts | 145 ++++++++++--------
...onent-groups-notAuthorized-rename-props.ts | 31 ++--
...Authorized-rename-to-unauthorizedAccess.md | 18 +++
...rized-rename-to-unauthorizedAccess.test.ts | 61 ++++++++
...Authorized-rename-to-unauthorizedAccess.ts | 12 ++
...horizedRenameToUnauthorizedAccessInput.tsx | 4 +
...orizedRenameToUnauthorizedAccessOutput.tsx | 4 +
.../data-codemods-cleanup.ts | 16 +-
21 files changed, 511 insertions(+), 160 deletions(-)
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.md
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.test.ts
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.ts
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderInput.tsx
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderOutput.tsx
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.md
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.test.ts
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.ts
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageInput.tsx
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageOutput.tsx
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.md
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.test.ts
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.ts
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessInput.tsx
create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessOutput.tsx
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts b/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts
index 5c78f3de6..4268e16db 100644
--- a/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts
+++ b/packages/eslint-plugin-pf-codemods/src/rules/helpers/renameComponent.ts
@@ -49,7 +49,17 @@ function getFixes(
);
}
- const shouldRenameNode =
+ let shouldRenameNode = false;
+
+ if (
+ nodeImport.type === "ImportDefaultSpecifier" &&
+ nodeImport.local.name === oldName
+ ) {
+ shouldRenameNode = true;
+ fixes.push(fixer.replaceText(nodeImport, newName));
+ }
+
+ shouldRenameNode ||=
isNamedImport && nodeImport.imported.name === nodeImport.local.name;
if (shouldRenameNode) {
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.md
new file mode 100644
index 000000000..04479452f
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.md
@@ -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%
+```
+
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.test.ts
new file mode 100644
index 000000000..bc251cfc9
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.test.ts
@@ -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: ``,
+ },
+ // import from wrong package
+ {
+ code: `import { ContentHeader } from '@patternfly/react-core'; `,
+ },
+ ],
+ invalid: [
+ {
+ code: `import { ContentHeader } from '@patternfly/react-component-groups'; `,
+ output: `import { PageHeader } from '@patternfly/react-component-groups'; `,
+ errors,
+ },
+ // named import with alias
+ {
+ code: `import { ContentHeader as Header } from '@patternfly/react-component-groups'; `,
+ output: `import { PageHeader as Header } from '@patternfly/react-component-groups'; `,
+ errors,
+ },
+ // default imports
+ {
+ code: `import ContentHeader from '@patternfly/react-component-groups/dist/cjs/ContentHeader/index'; `,
+ output: `import PageHeader from '@patternfly/react-component-groups/dist/cjs/PageHeader/index'; `,
+ errors,
+ },
+ {
+ code: `import ContentHeader from '@patternfly/react-component-groups/dist/esm/ContentHeader/index'; `,
+ output: `import PageHeader from '@patternfly/react-component-groups/dist/esm/PageHeader/index'; `,
+ errors,
+ },
+ {
+ code: `import ContentHeader from '@patternfly/react-component-groups/dist/dynamic/ContentHeader'; `,
+ output: `import PageHeader from '@patternfly/react-component-groups/dist/dynamic/PageHeader'; `,
+ errors,
+ },
+ // default import with name not matching the component name
+ {
+ code: `import Header from '@patternfly/react-component-groups/dist/dynamic/ContentHeader'; `,
+ output: `import Header from '@patternfly/react-component-groups/dist/dynamic/PageHeader'; `,
+ errors,
+ },
+ ],
+});
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.ts
new file mode 100644
index 000000000..24ed4006b
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/component-groups-contentHeader-rename-to-pageHeader.ts
@@ -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"
+ ),
+};
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderInput.tsx
new file mode 100644
index 000000000..df9ad8701
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderInput.tsx
@@ -0,0 +1,5 @@
+import { ContentHeader } from "@patternfly/react-component-groups";
+
+export const ComponentGroupsContentHeaderRenameToPageHeaderInput = () => (
+
+);
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderOutput.tsx
new file mode 100644
index 000000000..e9097d945
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsContentHeaderRenameToPageHeader/componentGroupsContentHeaderRenameToPageHeaderOutput.tsx
@@ -0,0 +1,5 @@
+import { PageHeader } from "@patternfly/react-component-groups";
+
+export const ComponentGroupsContentHeaderRenameToPageHeaderInput = () => (
+
+);
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.test.ts
index 85a01d4db..7697a4891 100644
--- a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.test.ts
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.test.ts
@@ -6,88 +6,99 @@ const renameMap = {
invalidObjectBodyText: "bodyText",
};
-const errors = Object.entries(renameMap).map(([oldName, newName]) => ({
- message: `The ${oldName} prop for InvalidObject has been renamed to ${newName}.`,
- type: "JSXOpeningElement",
-}));
+const getErrors = (component: string) =>
+ Object.entries(renameMap).map(([oldName, newName]) => ({
+ message: `The ${oldName} prop for ${component} has been renamed to ${newName}.`,
+ type: "JSXOpeningElement",
+ }));
-ruleTester.run("component-groups-invalidObject-rename-props", rule, {
- valid: [
+const components = ["InvalidObject", "MissingPage"];
+
+const valid = components
+ .map((component) => [
{
- code: ``,
+ code: `<${component} invalidObjectTitleText="" />`,
},
{
- code: ``,
+ code: `<${component} invalidObjectBodyText="" />`,
},
{
- code: `import { InvalidObject } from '@patternfly/react-component-groups'; `,
+ code: `import { ${component} } from '@patternfly/react-component-groups'; <${component} someOtherProp />`,
},
- ],
- invalid: [
+ ])
+ .flat();
+
+const invalid = components
+ .map((component) => [
{
- code: `import { InvalidObject } from '@patternfly/react-component-groups';
- `,
- output: `import { InvalidObject } from '@patternfly/react-component-groups';
- `,
- errors,
+ code: `import { ${component} } from '@patternfly/react-component-groups';
+ <${component}
+ invalidObjectTitleText="Sample title text"
+ invalidObjectBodyText="Sample body text"
+ />`,
+ output: `import { ${component} } from '@patternfly/react-component-groups';
+ <${component}
+ titleText="Sample title text"
+ bodyText="Sample body text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import InvalidObject from '@patternfly/react-component-groups/dist/cjs/InvalidObject/index';
- `,
- output: `import InvalidObject from '@patternfly/react-component-groups/dist/cjs/InvalidObject/index';
- `,
- errors,
+ code: `import ${component} from '@patternfly/react-component-groups/dist/cjs/${component}/index';
+ <${component}
+ invalidObjectTitleText="Sample title text"
+ invalidObjectBodyText="Sample body text"
+ />`,
+ output: `import ${component} from '@patternfly/react-component-groups/dist/cjs/${component}/index';
+ <${component}
+ titleText="Sample title text"
+ bodyText="Sample body text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import InvalidObject from '@patternfly/react-component-groups/dist/esm/InvalidObject/index';
- `,
- output: `import InvalidObject from '@patternfly/react-component-groups/dist/esm/InvalidObject/index';
- `,
- errors,
+ code: `import ${component} from '@patternfly/react-component-groups/dist/esm/${component}/index';
+ <${component}
+ invalidObjectTitleText="Sample title text"
+ invalidObjectBodyText="Sample body text"
+ />`,
+ output: `import ${component} from '@patternfly/react-component-groups/dist/esm/${component}/index';
+ <${component}
+ titleText="Sample title text"
+ bodyText="Sample body text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import InvalidObject from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
- `,
- output: `import InvalidObject from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
- `,
- errors,
+ code: `import ${component} from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ <${component}
+ invalidObjectTitleText="Sample title text"
+ invalidObjectBodyText="Sample body text"
+ />`,
+ output: `import ${component} from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ <${component}
+ titleText="Sample title text"
+ bodyText="Sample body text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
- `,
- output: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/InvalidObject';
- `,
- errors,
+ code: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ `,
+ output: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ `,
+ errors: getErrors(component),
},
- ],
+ ])
+ .flat();
+
+ruleTester.run("component-groups-invalidObject-rename-props", rule, {
+ valid,
+ invalid,
});
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.ts
index 7c5946978..4d80af822 100644
--- a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.ts
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameProps/component-groups-invalidObject-rename-props.ts
@@ -3,20 +3,27 @@ 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 formatMessage = (
+ component: string,
+ oldPropName: string,
+ newPropName: string
+) =>
+ `The ${oldPropName} prop for ${component} has been renamed to ${newPropName}.`;
-const renames: Renames = {
- InvalidObject: {
- invalidObjectTitleText: {
- newName: "titleText",
- message: formatMessage("invalidObjectTitleText", "titleText"),
- },
- invalidObjectBodyText: {
- newName: "bodyText",
- message: formatMessage("invalidObjectBodyText", "bodyText"),
- },
+const getPropsRenames = (component: string) => ({
+ invalidObjectTitleText: {
+ newName: "titleText",
+ message: formatMessage(component, "invalidObjectTitleText", "titleText"),
+ },
+ invalidObjectBodyText: {
+ newName: "bodyText",
+ message: formatMessage(component, "invalidObjectBodyText", "bodyText"),
},
+});
+
+const renames: Renames = {
+ InvalidObject: getPropsRenames("InvalidObject"),
+ MissingPage: getPropsRenames("MissingPage"),
};
module.exports = {
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.md
new file mode 100644
index 000000000..7711eadea
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.md
@@ -0,0 +1,18 @@
+### component-groups-invalidObject-rename-to-missingPage [(react-component-groups/#313)](https://github.com/patternfly/react-component-groups/pull/313)
+
+In react-component-groups, we've renamed InvalidObject component to MissingPage
+
+#### Examples
+
+In:
+
+```jsx
+%inputExample%
+```
+
+Out:
+
+```jsx
+%outputExample%
+```
+
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.test.ts
new file mode 100644
index 000000000..c3179d6fc
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.test.ts
@@ -0,0 +1,57 @@
+const ruleTester = require("../../ruletester");
+import * as rule from "./component-groups-invalidObject-rename-to-missingPage";
+
+const errors = [
+ {
+ message: `InvalidObject has been renamed to MissingPage.`,
+ type: "JSXOpeningElement",
+ },
+];
+
+ruleTester.run("component-groups-invalidObject-rename-to-missingPage", rule, {
+ valid: [
+ // missing import
+ {
+ code: ``,
+ },
+ // import from wrong package
+ {
+ code: `import { InvalidObject } from '@patternfly/react-core'; `,
+ },
+ ],
+ invalid: [
+ {
+ code: `import { InvalidObject } from '@patternfly/react-component-groups'; `,
+ output: `import { MissingPage } from '@patternfly/react-component-groups'; `,
+ errors,
+ },
+ // named import with alias
+ {
+ code: `import { InvalidObject as InvObj } from '@patternfly/react-component-groups'; `,
+ output: `import { MissingPage as InvObj } from '@patternfly/react-component-groups'; `,
+ errors,
+ },
+ // default imports
+ {
+ code: `import InvalidObject from '@patternfly/react-component-groups/dist/cjs/InvalidObject/index'; `,
+ output: `import MissingPage from '@patternfly/react-component-groups/dist/cjs/MissingPage/index'; `,
+ errors,
+ },
+ {
+ code: `import InvalidObject from '@patternfly/react-component-groups/dist/esm/InvalidObject/index'; `,
+ output: `import MissingPage from '@patternfly/react-component-groups/dist/esm/MissingPage/index'; `,
+ errors,
+ },
+ {
+ code: `import InvalidObject from '@patternfly/react-component-groups/dist/dynamic/InvalidObject'; `,
+ output: `import MissingPage from '@patternfly/react-component-groups/dist/dynamic/MissingPage'; `,
+ errors,
+ },
+ // default import with name not matching the component name
+ {
+ code: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/InvalidObject'; `,
+ output: `import InvObj from '@patternfly/react-component-groups/dist/dynamic/MissingPage'; `,
+ errors,
+ },
+ ],
+});
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.ts
new file mode 100644
index 000000000..0483ecf76
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/component-groups-invalidObject-rename-to-missingPage.ts
@@ -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(
+ {
+ InvalidObject: "MissingPage",
+ },
+ "@patternfly/react-component-groups"
+ ),
+};
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageInput.tsx
new file mode 100644
index 000000000..7ffe08897
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageInput.tsx
@@ -0,0 +1,4 @@
+import { InvalidObject } from "@patternfly/react-component-groups";
+
+export const ComponentGroupsInvalidObjectRenameToMissingPageInput =
+ () => ;
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageOutput.tsx
new file mode 100644
index 000000000..d4e150cf3
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsInvalidObjectRenameToMissingPage/componentGroupsInvalidObjectRenameToMissingPageOutput.tsx
@@ -0,0 +1,4 @@
+import { MissingPage } from "@patternfly/react-component-groups";
+
+export const ComponentGroupsInvalidObjectRenameToMissingPageInput =
+ () => ;
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.test.ts
index 4c09f68b9..121eaf076 100644
--- a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.test.ts
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.test.ts
@@ -6,88 +6,99 @@ const renameMap = {
title: "titleText",
};
-const errors = Object.entries(renameMap).map(([oldName, newName]) => ({
- message: `The ${oldName} prop for NotAuthorized has been renamed to ${newName}.`,
- type: "JSXOpeningElement",
-}));
+const getErrors = (component: string) =>
+ Object.entries(renameMap).map(([oldName, newName]) => ({
+ message: `The ${oldName} prop for ${component} has been renamed to ${newName}.`,
+ type: "JSXOpeningElement",
+ }));
-ruleTester.run("component-groups-notAuthorized-rename-props", rule, {
- valid: [
+const components = ["NotAuthorized", "UnauthorizedAccess"];
+
+const valid = components
+ .map((component) => [
{
- code: ``,
+ code: `<${component} description="" />`,
},
{
- code: ``,
+ code: `<${component} title="" />`,
},
{
- code: `import { NotAuthorized } from '@patternfly/react-component-groups'; `,
+ code: `import { ${component} } from '@patternfly/react-component-groups'; <${component} someOtherProp />`,
},
- ],
- invalid: [
+ ])
+ .flat();
+
+const invalid = components
+ .map((component) => [
{
- code: `import { NotAuthorized } from '@patternfly/react-component-groups';
- `,
- output: `import { NotAuthorized } from '@patternfly/react-component-groups';
- `,
- errors,
+ code: `import { ${component} } from '@patternfly/react-component-groups';
+ <${component}
+ description="Description text"
+ title="Title text"
+ />`,
+ output: `import { ${component} } from '@patternfly/react-component-groups';
+ <${component}
+ bodyText="Description text"
+ titleText="Title text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import NotAuthorized from '@patternfly/react-component-groups/dist/cjs/NotAuthorized/index';
- `,
- output: `import NotAuthorized from '@patternfly/react-component-groups/dist/cjs/NotAuthorized/index';
- `,
- errors,
+ code: `import ${component} from '@patternfly/react-component-groups/dist/cjs/${component}/index';
+ <${component}
+ description="Description text"
+ title="Title text"
+ />`,
+ output: `import ${component} from '@patternfly/react-component-groups/dist/cjs/${component}/index';
+ <${component}
+ bodyText="Description text"
+ titleText="Title text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import NotAuthorized from '@patternfly/react-component-groups/dist/esm/NotAuthorized/index';
- `,
- output: `import NotAuthorized from '@patternfly/react-component-groups/dist/esm/NotAuthorized/index';
- `,
- errors,
+ code: `import ${component} from '@patternfly/react-component-groups/dist/esm/${component}/index';
+ <${component}
+ description="Description text"
+ title="Title text"
+ />`,
+ output: `import ${component} from '@patternfly/react-component-groups/dist/esm/${component}/index';
+ <${component}
+ bodyText="Description text"
+ titleText="Title text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import NotAuthorized from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
- `,
- output: `import NotAuthorized from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
- `,
- errors,
+ code: `import ${component} from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ <${component}
+ description="Description text"
+ title="Title text"
+ />`,
+ output: `import ${component} from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ <${component}
+ bodyText="Description text"
+ titleText="Title text"
+ />`,
+ errors: getErrors(component),
},
{
- code: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
- `,
- output: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized';
- `,
- errors,
+ code: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ `,
+ output: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/${component}';
+ `,
+ errors: getErrors(component),
},
- ],
+ ])
+ .flat();
+
+ruleTester.run("component-groups-notAuthorized-rename-props", rule, {
+ valid,
+ invalid,
});
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.ts
index 01b27666a..36d1aa923 100644
--- a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.ts
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameProps/component-groups-notAuthorized-rename-props.ts
@@ -3,20 +3,27 @@ import { Renames } from "../../helpers/renameSinglePropOnNode";
// https://github.com/patternfly/react-component-groups/pull/145
-const formatMessage = (oldPropName: string, newPropName: string) =>
- `The ${oldPropName} prop for NotAuthorized has been renamed to ${newPropName}.`;
+const formatMessage = (
+ component: string,
+ oldPropName: string,
+ newPropName: string
+) =>
+ `The ${oldPropName} prop for ${component} has been renamed to ${newPropName}.`;
-const renames: Renames = {
- NotAuthorized: {
- description: {
- newName: "bodyText",
- message: formatMessage("description", "bodyText"),
- },
- title: {
- newName: "titleText",
- message: formatMessage("title", "titleText"),
- },
+const getPropsRenames = (component: string) => ({
+ description: {
+ newName: "bodyText",
+ message: formatMessage(component, "description", "bodyText"),
+ },
+ title: {
+ newName: "titleText",
+ message: formatMessage(component, "title", "titleText"),
},
+});
+
+const renames: Renames = {
+ NotAuthorized: getPropsRenames("NotAuthorized"),
+ UnauthorizedAccess: getPropsRenames("UnauthorizedAccess"),
};
module.exports = {
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.md
new file mode 100644
index 000000000..b029280ad
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.md
@@ -0,0 +1,18 @@
+### component-groups-notAuthorized-rename-to-unauthorizedAccess [(react-component-groups/#313)](https://github.com/patternfly/react-component-groups/pull/313)
+
+In react-component-groups, we've renamed NotAuthorized component to UnauthorizedAccess
+
+#### Examples
+
+In:
+
+```jsx
+%inputExample%
+```
+
+Out:
+
+```jsx
+%outputExample%
+```
+
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.test.ts
new file mode 100644
index 000000000..4d7de0056
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.test.ts
@@ -0,0 +1,61 @@
+const ruleTester = require("../../ruletester");
+import * as rule from "./component-groups-notAuthorized-rename-to-unauthorizedAccess";
+
+const errors = [
+ {
+ message: `NotAuthorized has been renamed to UnauthorizedAccess.`,
+ type: "JSXOpeningElement",
+ },
+];
+
+ruleTester.run(
+ "component-groups-notAuthorized-rename-to-unauthorizedAccess",
+ rule,
+ {
+ valid: [
+ // missing import
+ {
+ code: ``,
+ },
+ // import from wrong package
+ {
+ code: `import { NotAuthorized } from '@patternfly/react-core'; `,
+ },
+ ],
+ invalid: [
+ {
+ code: `import { NotAuthorized } from '@patternfly/react-component-groups'; `,
+ output: `import { UnauthorizedAccess } from '@patternfly/react-component-groups'; `,
+ errors,
+ },
+ // named import with alias
+ {
+ code: `import { NotAuthorized as NotAuth } from '@patternfly/react-component-groups'; `,
+ output: `import { UnauthorizedAccess as NotAuth } from '@patternfly/react-component-groups'; `,
+ errors,
+ },
+ // default imports
+ {
+ code: `import NotAuthorized from '@patternfly/react-component-groups/dist/cjs/NotAuthorized/index'; `,
+ output: `import UnauthorizedAccess from '@patternfly/react-component-groups/dist/cjs/UnauthorizedAccess/index'; `,
+ errors,
+ },
+ {
+ code: `import NotAuthorized from '@patternfly/react-component-groups/dist/esm/NotAuthorized/index'; `,
+ output: `import UnauthorizedAccess from '@patternfly/react-component-groups/dist/esm/UnauthorizedAccess/index'; `,
+ errors,
+ },
+ {
+ code: `import NotAuthorized from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized'; `,
+ output: `import UnauthorizedAccess from '@patternfly/react-component-groups/dist/dynamic/UnauthorizedAccess'; `,
+ errors,
+ },
+ // default import with name not matching the component name
+ {
+ code: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/NotAuthorized'; `,
+ output: `import NotAuth from '@patternfly/react-component-groups/dist/dynamic/UnauthorizedAccess'; `,
+ errors,
+ },
+ ],
+ }
+);
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.ts
new file mode 100644
index 000000000..02ec4787c
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/component-groups-notAuthorized-rename-to-unauthorizedAccess.ts
@@ -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(
+ {
+ NotAuthorized: "UnauthorizedAccess",
+ },
+ "@patternfly/react-component-groups"
+ ),
+};
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessInput.tsx
new file mode 100644
index 000000000..cb0fbde07
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessInput.tsx
@@ -0,0 +1,4 @@
+import { NotAuthorized } from "@patternfly/react-component-groups";
+
+export const ComponentGroupsNotAuthorizedRenameToUnauthorizedAccessInput =
+ () => ;
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessOutput.tsx
new file mode 100644
index 000000000..03e22d9ec
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/componentGroupsNotAuthorizedRenameToUnauthorizedAccess/componentGroupsNotAuthorizedRenameToUnauthorizedAccessOutput.tsx
@@ -0,0 +1,4 @@
+import { UnauthorizedAccess } from "@patternfly/react-component-groups";
+
+export const ComponentGroupsNotAuthorizedRenameToUnauthorizedAccessInput =
+ () => ;
diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/dataCodemodsCleanup/data-codemods-cleanup.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/dataCodemodsCleanup/data-codemods-cleanup.ts
index 21979176b..c89e36844 100644
--- a/packages/eslint-plugin-pf-codemods/src/rules/v6/dataCodemodsCleanup/data-codemods-cleanup.ts
+++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/dataCodemodsCleanup/data-codemods-cleanup.ts
@@ -3,6 +3,7 @@ import { ImportSpecifier, JSXOpeningElement } from "estree-jsx";
import {
checkMatchingJSXOpeningElement,
getAttribute,
+ getDefaultImportsFromPackage,
getFromPackage,
} from "../../helpers";
@@ -17,8 +18,21 @@ module.exports = {
context,
"@patternfly/react-table"
);
+ const { imports: componentGroupsImports } = getFromPackage(
+ context,
+ "@patternfly/react-component-groups"
+ );
+ const componentGroupsDefaultImports = getDefaultImportsFromPackage(
+ context,
+ "@patternfly/react-component-groups"
+ );
- const imports = [...coreImports, ...tableImports];
+ const imports = [
+ ...coreImports,
+ ...tableImports,
+ ...componentGroupsImports,
+ ...componentGroupsDefaultImports,
+ ];
const message =
"This rule will remove data-codemods attributes and comments, which were introduced by our codemods in order to work correctly.";