From 3d0cbb11a5fdba8977ec8da6ef51ae2a710658af Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Tue, 27 Feb 2024 13:50:47 -0500 Subject: [PATCH] feat(Card): Remove deprecated and unused props (#591) * feat(Card): Remove deprecated and unused props * chore(Card): Bring md inline with other rules, unpretty tsx output file --- .../card-remove-various-props.md | 25 ++++++ .../card-remove-various-props.test.ts | 77 +++++++++++++++++++ .../card-remove-various-props.ts | 40 ++++++++++ .../cardRemoveVariousPropsInput.tsx | 11 +++ .../cardRemoveVariousPropsOutput.tsx | 11 +++ 5 files changed, 164 insertions(+) create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.md create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.test.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsInput.tsx create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsOutput.tsx diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.md new file mode 100644 index 000000000..9c389c91c --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.md @@ -0,0 +1,25 @@ +### card-remove-various-props [(#10056)](https://github.com/patternfly/patternfly-react/pull/10056) + +The following props have been removed from Card: +- isSelectableRaised +- isDisabledRaised +- hasSelectableInput +- selectableInputAriaLabel +- onSelectableInputChange +- isFlat +- isRounded + +#### Examples + +In: + +```jsx +%inputExample% +``` + +Out: + +```jsx +%outputExample% +``` + diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.test.ts new file mode 100644 index 000000000..df5cba482 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.test.ts @@ -0,0 +1,77 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./card-remove-various-props"; + +interface InvalidTest { + code: string; + output: string; + errors: { message: string }[]; +} + +const removedBooleanProps = [ + "isSelectableRaised", + "isDisabledRaised", + "hasSelectableInput", + "isFlat", + "isRounded", +]; +const removedStringProps = ["selectableInputAriaLabel"]; +const removedFunctionProps = ["onSelectableInputChange"]; + +const removedBooleanPropTests = removedBooleanProps.map((prop) => ({ + code: `import { Card } from '@patternfly/react-core'; `, + output: `import { Card } from '@patternfly/react-core'; `, + errors: [{ message: `The ${prop} prop has been removed` }], +})); + +const removedStringPropTests = removedStringProps.reduce((acc, prop) => { + return [ + ...acc, + { + code: `import { Card } from '@patternfly/react-core'; `, + output: `import { Card } from '@patternfly/react-core'; `, + errors: [{ message: `The ${prop} prop has been removed` }], + }, + { + code: `import { Card } from '@patternfly/react-core'; const foo = "foo bar"; `, + output: `import { Card } from '@patternfly/react-core'; const foo = "foo bar"; `, + errors: [{ message: `The ${prop} prop has been removed` }], + }, + ]; +}, [] as InvalidTest[]); + +const removedFunctionPropTests = removedFunctionProps.reduce((acc, prop) => { + return [ + ...acc, + { + code: `import { Card } from '@patternfly/react-core'; {}} />`, + output: `import { Card } from '@patternfly/react-core'; `, + errors: [{ message: `The ${prop} prop has been removed` }], + }, + { + code: `import { Card } from '@patternfly/react-core'; const foo = () => {}; `, + output: `import { Card } from '@patternfly/react-core'; const foo = () => {}; `, + errors: [{ message: `The ${prop} prop has been removed` }], + }, + { + code: `import { Card } from '@patternfly/react-core'; function foo() {}; `, + output: `import { Card } from '@patternfly/react-core'; function foo() {}; `, + errors: [{ message: `The ${prop} prop has been removed` }], + }, + ]; +}, [] as InvalidTest[]); + +ruleTester.run("card-remove-various-props", rule, { + valid: [ + { + code: ` {}} isFlat isRounded />`, + }, + { + code: `import { Card } from '@patternfly/react-core'; `, + }, + ], + invalid: [ + ...removedBooleanPropTests, + ...removedStringPropTests, + ...removedFunctionPropTests, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.ts new file mode 100644 index 000000000..1d24b241f --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/card-remove-various-props.ts @@ -0,0 +1,40 @@ +import { renameProps } from "../../helpers"; + +// https://github.com/patternfly/patternfly-react/pull/10056 +const formatMessage = (propName: string) => + `The ${propName} prop has been removed`; +module.exports = { + meta: { fixable: "code" }, + create: renameProps({ + Card: { + isSelectableRaised: { + newName: "", + message: formatMessage("isSelectableRaised"), + }, + isDisabledRaised: { + newName: "", + message: formatMessage("isDisabledRaised"), + }, + hasSelectableInput: { + newName: "", + message: formatMessage("hasSelectableInput"), + }, + selectableInputAriaLabel: { + newName: "", + message: formatMessage("selectableInputAriaLabel"), + }, + onSelectableInputChange: { + newName: "", + message: formatMessage("onSelectableInputChange"), + }, + isFlat: { + newName: "", + message: formatMessage("isFlat"), + }, + isRounded: { + newName: "", + message: formatMessage("isRounded"), + }, + }, + }), +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsInput.tsx new file mode 100644 index 000000000..b204d0e24 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsInput.tsx @@ -0,0 +1,11 @@ +import { Card } from "@patternfly/react-core"; + +export const CardRemoveVariousPropsInput = () => ( + {}} + /> +); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsOutput.tsx new file mode 100644 index 000000000..05d9984b4 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/cardRemoveVariousProps/cardRemoveVariousPropsOutput.tsx @@ -0,0 +1,11 @@ +import { Card } from "@patternfly/react-core"; + +export const CardRemoveVariousPropsInput = () => ( + +);