From d9368030336ea29457ccfeeab7e4c87845569168 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 8 Jul 2024 14:18:01 -0400 Subject: [PATCH] fix(WizardStep): prevented omitting the WizardBody component --- .../wizardStep-updated-body-typing.md | 17 +++++ .../wizardStep-updated-body-typing.test.ts | 68 +++++++++++++++++++ .../wizardStep-updated-body-typing.ts | 42 ++++++++++++ .../wizardStepUpdatedBodyTypingInput.tsx | 5 ++ .../wizardStepUpdatedBodyTypingOutput.tsx | 5 ++ 5 files changed, 137 insertions(+) create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.md create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.test.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingInput.tsx create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingOutput.tsx diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.md new file mode 100644 index 000000000..46e8d201d --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.md @@ -0,0 +1,17 @@ +### wizardStep-updated-body-typing [(#10637)](https://github.com/patternfly/patternfly-react/pull/10637) + +The `body` prop on WizardStep no longer accepts a value of "null". + +#### Examples + +In: + +```jsx +%inputExample% +``` + +Out: + +```jsx +%outputExample% +``` diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.test.ts new file mode 100644 index 000000000..06bb13b1c --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.test.ts @@ -0,0 +1,68 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./wizardStep-updated-body-typing"; + +ruleTester.run("wizardStep-updated-body-typing", rule, { + valid: [ + { + code: ``, + }, + { + code: `import { WizardStep } from '@patternfly/react-core'; `, + }, + { + code: `import { WizardStep } from '@patternfly/react-core'; `, + }, + ], + invalid: [ + { + code: `import { WizardStep } from '@patternfly/react-core'; `, + output: `import { WizardStep } from '@patternfly/react-core'; `, + errors: [ + { + message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`, + type: "JSXOpeningElement", + }, + ], + }, + { + code: `import { WizardStep } from '@patternfly/react-core'; const bodyProp = null; `, + output: `import { WizardStep } from '@patternfly/react-core'; const bodyProp = null; `, + errors: [ + { + message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`, + type: "JSXOpeningElement", + }, + ], + }, + { + code: `import { WizardStep } from '@patternfly/react-core/dist/esm/components/Wizard/index.js'; `, + output: `import { WizardStep } from '@patternfly/react-core/dist/esm/components/Wizard/index.js'; `, + errors: [ + { + message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`, + type: "JSXOpeningElement", + }, + ], + }, + { + code: `import { WizardStep } from '@patternfly/react-core/dist/js/components/Wizard/index.js'; `, + output: `import { WizardStep } from '@patternfly/react-core/dist/js/components/Wizard/index.js'; `, + errors: [ + { + message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`, + type: "JSXOpeningElement", + }, + ], + }, + { + code: `import { WizardStep } from '@patternfly/react-core/dist/dynamic/components/Wizard/index.js'; `, + output: `import { WizardStep } from '@patternfly/react-core/dist/dynamic/components/Wizard/index.js'; `, + errors: [ + { + message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`, + type: "JSXOpeningElement", + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.ts new file mode 100644 index 000000000..b66f3ed70 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStep-updated-body-typing.ts @@ -0,0 +1,42 @@ +import { Rule } from "eslint"; +import { JSXOpeningElement } from "estree-jsx"; +import { getFromPackage, getAttribute, getAttributeValue } from "../../helpers"; + +// https://github.com/patternfly/patternfly-react/pull/10637 +module.exports = { + meta: { fixable: "code" }, + create: function (context: Rule.RuleContext) { + const { imports } = getFromPackage(context, "@patternfly/react-core"); + + const wizardStepImport = imports.find( + (specifier) => specifier.imported.name === "WizardStep" + ); + + return !wizardStepImport + ? {} + : { + JSXOpeningElement(node: JSXOpeningElement) { + if ( + node.name.type === "JSXIdentifier" && + wizardStepImport.local.name === node.name.name + ) { + const bodyProp = getAttribute(node, "body"); + if (!bodyProp) { + return; + } + const bodyValue = getAttributeValue(context, bodyProp.value); + + if (bodyValue === null) { + context.report({ + node, + message: `The \`body\` prop on WizardStep no longer accepts a value of "null".`, + fix(fixer) { + return fixer.replaceText(bodyProp, ""); + }, + }); + } + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingInput.tsx new file mode 100644 index 000000000..724a5b2e3 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingInput.tsx @@ -0,0 +1,5 @@ +import { WizardStep } from "@patternfly/react-core"; + +export const WizardStepUpdatedBodyTypingInput = () => ( + +); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingOutput.tsx new file mode 100644 index 000000000..073775a66 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/wizardStepUpdatedBodyTyping/wizardStepUpdatedBodyTypingOutput.tsx @@ -0,0 +1,5 @@ +import { WizardStep } from "@patternfly/react-core"; + +export const WizardStepUpdatedBodyTypingInput = () => ( + +);