diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.md new file mode 100644 index 000000000..fb49ab86d --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.md @@ -0,0 +1,17 @@ +### checkbox-radio-replace-isLabelBeforeButton [(#10016)](https://github.com/patternfly/patternfly-react/pull/10016) + +The `isLabelBeforeButton` prop in Checkbox and Radio has been replaced with `labelPosition="start"` + +#### Examples + +In: + +```jsx +%inputExample% +``` + +Out: + +```jsx +%outputExample% +``` diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.test.ts new file mode 100644 index 000000000..468ea5dd3 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.test.ts @@ -0,0 +1,29 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./checkbox-radio-replace-isLabelBeforeButton"; + +ruleTester.run("checkbox-radio-replace-isLabelBeforeButton", rule, { + valid: [ + { + code: ``, + }, + { + code: `import { Checkbox } from '@patternfly/react-core'; `, + }, + { + code: ``, + }, + { + code: `import { Radio } from '@patternfly/react-core'; `, + }, + ], + invalid: ["Checkbox", "Radio"].map((component) => ({ + code: `import { ${component} } from '@patternfly/react-core'; <${component} isLabelBeforeButton />`, + output: `import { ${component} } from '@patternfly/react-core'; <${component} labelPosition="start" />`, + errors: [ + { + message: `isLabelBeforeButton prop for ${component} has been replaced with labelPosition="start"`, + type: "JSXOpeningElement", + }, + ], + })), +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.ts new file mode 100644 index 000000000..f20b0e3e9 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkbox-radio-replace-isLabelBeforeButton.ts @@ -0,0 +1,17 @@ +import { renameProps } from "../../helpers"; + +const renames = { + isLabelBeforeButton: { + newName: 'labelPosition="start"', + replace: true, + }, +}; + +// https://github.com/patternfly/patternfly-react/pull/10016 +module.exports = { + meta: { fixable: "code" }, + create: renameProps({ + Checkbox: renames, + Radio: renames, + }), +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkboxRadioReplaceIsLabelBeforeButtonInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkboxRadioReplaceIsLabelBeforeButtonInput.tsx new file mode 100644 index 000000000..38e481961 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkboxRadioReplaceIsLabelBeforeButtonInput.tsx @@ -0,0 +1,8 @@ +import { Checkbox, Radio } from "@patternfly/react-core"; + +export const CheckboxReplaceIsLabelBeforeButtonInput = () => ( + +); +export const RadioReplaceIsLabelBeforeButtonInput = () => ( + +); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkboxRadioReplaceIsLabelBeforeButtonOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkboxRadioReplaceIsLabelBeforeButtonOutput.tsx new file mode 100644 index 000000000..f877281d5 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/checkboxRadioReplaceIsLabelBeforeButton/checkboxRadioReplaceIsLabelBeforeButtonOutput.tsx @@ -0,0 +1,8 @@ +import { Checkbox, Radio } from "@patternfly/react-core"; + +export const CheckboxReplaceIsLabelBeforeButtonInput = () => ( + +); +export const RadioReplaceIsLabelBeforeButtonInput = () => ( + +);