From 7a6588b87ec03ead43ae92ef04452e8ca21b6726 Mon Sep 17 00:00:00 2001 From: Eric Olkowski Date: Mon, 6 Mar 2023 09:51:46 -0500 Subject: [PATCH 1/2] fix(DataListCheck): reordered onChange params --- packages/eslint-plugin-pf-codemods/index.js | 1 + .../v5/dataListCheck-warn-updated-callback.js | 27 ++++++++++++++ .../v5/dataListCheck-warn-updated-callback.js | 36 +++++++++++++++++++ packages/pf-codemods/README.md | 6 ++++ test/test.tsx | 2 ++ 5 files changed, 72 insertions(+) create mode 100644 packages/eslint-plugin-pf-codemods/lib/rules/v5/dataListCheck-warn-updated-callback.js create mode 100644 packages/eslint-plugin-pf-codemods/test/rules/v5/dataListCheck-warn-updated-callback.js diff --git a/packages/eslint-plugin-pf-codemods/index.js b/packages/eslint-plugin-pf-codemods/index.js index 5230d3ccd..22f8f51cf 100644 --- a/packages/eslint-plugin-pf-codemods/index.js +++ b/packages/eslint-plugin-pf-codemods/index.js @@ -21,6 +21,7 @@ const warningRules = [ "applicationLauncher-warn-input", "card-warn-component", "charts-tooltip-warning", + "dataListCheck-warn-updated-callback", "datePicker-warn-appendTo-default-value-changed", "horizontalSubnav-ariaLabel", "nav-warn-flyouts-now-inline", diff --git a/packages/eslint-plugin-pf-codemods/lib/rules/v5/dataListCheck-warn-updated-callback.js b/packages/eslint-plugin-pf-codemods/lib/rules/v5/dataListCheck-warn-updated-callback.js new file mode 100644 index 000000000..02d8cc684 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/lib/rules/v5/dataListCheck-warn-updated-callback.js @@ -0,0 +1,27 @@ +const { getPackageImports } = require("../../helpers"); + +// https://github.com/patternfly/patternfly-react/pull/8735 +module.exports = { + meta: {}, + create: function (context) { + const imports = getPackageImports(context, "@patternfly/react-core").filter( + (specifier) => specifier.imported.name === "DataListCheck" + ); + + return imports.length === 0 + ? {} + : { + JSXOpeningElement(node) { + if ( + imports.map((imp) => imp.local.name).includes(node.name.name) && + node.attributes.find((attr) => attr.name.name === "onChange") + ) { + context.report({ + node, + message: `The "onChange" prop for DataListCheck has been updated so that the event parameter is the first parameter. "onChange" handlers may require an update.`, + }); + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/test/rules/v5/dataListCheck-warn-updated-callback.js b/packages/eslint-plugin-pf-codemods/test/rules/v5/dataListCheck-warn-updated-callback.js new file mode 100644 index 000000000..7d913027d --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/test/rules/v5/dataListCheck-warn-updated-callback.js @@ -0,0 +1,36 @@ +const ruleTester = require("../../ruletester"); +const rule = require("../../../lib/rules/v5/dataListCheck-warn-updated-callback"); + +ruleTester.run("dataListCheck-warn-updated-callback", rule, { + valid: [ + { + code: `import { DataListCheck } from '@patternfly/react-core'; ;`, + }, + { + // No @patternfly/react-core import + code: `;`, + }, + ], + invalid: [ + { + code: `import { DataListCheck } from '@patternfly/react-core'; ;`, + output: `import { DataListCheck } from '@patternfly/react-core'; ;`, + errors: [ + { + message: `The "onChange" prop for DataListCheck has been updated so that the event parameter is the first parameter. "onChange" handlers may require an update.`, + type: "JSXOpeningElement", + }, + ], + }, + { + code: `import { DataListCheck as PFdlc } from '@patternfly/react-core'; ;`, + output: `import { DataListCheck as PFdlc } from '@patternfly/react-core'; ;`, + errors: [ + { + message: `The "onChange" prop for DataListCheck has been updated so that the event parameter is the first parameter. "onChange" handlers may require an update.`, + type: "JSXOpeningElement", + }, + ], + }, + ], +}); diff --git a/packages/pf-codemods/README.md b/packages/pf-codemods/README.md index 49181c800..1e17c0b9d 100644 --- a/packages/pf-codemods/README.md +++ b/packages/pf-codemods/README.md @@ -359,6 +359,12 @@ function toggle2(_event, id) {}; ``` +### dataListCheck-warn-updated-callback [(#8735)](https://github.com/patternfly/patternfly-react/pull/8735) + +We've updated the `onChange` prop for DataListCheck so that the `event` parameter is the first parameter. Handlers may require an update. + +This rule will raise a warning, but will not make any changes. + ### datePicker-warn-appendTo-default-value-changed [(#8636)](https://github.com/patternfly/patternfly-react/pull/8636) The default value of the `appendTo` prop on DatePicker has been updated, which may cause markup changes that require updating selectors in tests. This rule will raise a warning, but will not make any changes. diff --git a/test/test.tsx b/test/test.tsx index e20d07f1e..6b31cc5eb 100644 --- a/test/test.tsx +++ b/test/test.tsx @@ -15,6 +15,7 @@ import { Button, Card, DataList, + DataListCheck, DatePicker, DropdownItem, DropdownToggle, @@ -56,6 +57,7 @@ const newTheme = getCustomTheme("1", "2", "3");