diff --git a/packages/eslint-plugin-pf-codemods/index.js b/packages/eslint-plugin-pf-codemods/index.js
index be6d68e80..5230d3ccd 100644
--- a/packages/eslint-plugin-pf-codemods/index.js
+++ b/packages/eslint-plugin-pf-codemods/index.js
@@ -1,7 +1,11 @@
const createListOfRules = (version) => {
const rules = {};
require("glob")
- .sync(require.resolve('@patternfly/eslint-plugin-pf-codemods').replace('index.js', `lib/rules/v${version}/*.js`))
+ .sync(
+ require
+ .resolve("@patternfly/eslint-plugin-pf-codemods")
+ .replace("index.js", `lib/rules/v${version}/*.js`)
+ )
.forEach(function (file) {
const ruleName = /.*\/([^.]+)/.exec(file)[1];
rules[ruleName] = require(`./lib/rules/v${version}/${ruleName}`);
@@ -19,7 +23,6 @@ const warningRules = [
"charts-tooltip-warning",
"datePicker-warn-appendTo-default-value-changed",
"horizontalSubnav-ariaLabel",
- "onToggle-warn-event",
"nav-warn-flyouts-now-inline",
"popover-appendTo-default",
"react-dropzone-warn-upgrade",
diff --git a/packages/eslint-plugin-pf-codemods/lib/helpers.js b/packages/eslint-plugin-pf-codemods/lib/helpers.js
index 787c01d85..eca3b7494 100644
--- a/packages/eslint-plugin-pf-codemods/lib/helpers.js
+++ b/packages/eslint-plugin-pf-codemods/lib/helpers.js
@@ -178,6 +178,90 @@ function ensureImports(context, node, package, imports) {
}
}
+function addCallbackParam(componentsArray, propMap) {
+ return function (context) {
+ const imports = getPackageImports(context, "@patternfly/react-core").filter(
+ (specifier) => componentsArray.includes(specifier.imported.name)
+ );
+
+ return !imports.length
+ ? {}
+ : {
+ JSXOpeningElement(node) {
+ if (imports.map((imp) => imp.local.name).includes(node.name.name)) {
+ const namedAttributes = node.attributes.filter((attr) =>
+ Object.keys(propMap).includes(attr.name?.name)
+ );
+
+ namedAttributes.forEach((attribute) => {
+ const newParam = propMap[attribute.name.name];
+
+ const propProperties = {
+ type: attribute.value?.expression?.type,
+ name: attribute.value?.expression?.name,
+ };
+
+ if (propProperties.type === "ArrowFunctionExpression") {
+ propProperties.params = attribute.value?.expression?.params;
+ } else if (propProperties.type === "Identifier") {
+ const currentScope = context.getScope();
+ const matchingVariable = currentScope.variables.find(
+ (variable) => variable.name === propProperties.name
+ );
+ const matchingDefinition = matchingVariable.defs.find(
+ (def) => def.name.name === propProperties.name
+ );
+
+ propProperties.params =
+ matchingDefinition.type === "FunctionName"
+ ? matchingDefinition.node.params
+ : matchingDefinition.node.init.params;
+ }
+ const { type, params } = propProperties;
+
+ if (
+ (params?.length === 1 &&
+ ["ArrowFunctionExpression", "Identifier"].includes(type)) ||
+ type === "MemberExpression"
+ ) {
+ context.report({
+ node,
+ message: `The "${attribute.name.name}" prop for ${node.name.name} has been updated to include the "${newParam}" parameter as its first parameter. "${attribute.name.name}" handlers may require an update.`,
+ fix(fixer) {
+ const fixes = [];
+ const createReplacerFix = (functionParam) => {
+ const hasParenthesis =
+ context.getTokenAfter(functionParam).value === ")";
+ const replacementParams = `${newParam}, ${functionParam.name}`;
+
+ return fixer.replaceText(
+ functionParam,
+ hasParenthesis
+ ? replacementParams
+ : `(${replacementParams})`
+ );
+ };
+
+ if (
+ ["ArrowFunctionExpression", "Identifier"].includes(
+ type
+ ) &&
+ params.length === 1
+ ) {
+ fixes.push(createReplacerFix(params[0]));
+ }
+
+ return fixes;
+ },
+ });
+ }
+ });
+ }
+ },
+ };
+ };
+}
+
module.exports = {
ensureImports,
getPackageImports,
@@ -185,4 +269,5 @@ module.exports = {
renameProps0,
renameProps,
renameComponents,
+ addCallbackParam
}
diff --git a/packages/eslint-plugin-pf-codemods/lib/rules/v5/dataList-updated-callback.js b/packages/eslint-plugin-pf-codemods/lib/rules/v5/dataList-updated-callback.js
new file mode 100644
index 000000000..4be374fdb
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/lib/rules/v5/dataList-updated-callback.js
@@ -0,0 +1,7 @@
+const { addCallbackParam } = require("../../helpers");
+
+// https://github.com/patternfly/patternfly-react/pull/8723
+module.exports = {
+ meta: { fixable: "code" },
+ create: addCallbackParam(["DataList"], { onSelectDataListItem: "_event" }),
+};
diff --git a/packages/eslint-plugin-pf-codemods/lib/rules/v5/onToggle-updated-paramaters.js b/packages/eslint-plugin-pf-codemods/lib/rules/v5/onToggle-updated-paramaters.js
new file mode 100644
index 000000000..942ad680b
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/lib/rules/v5/onToggle-updated-paramaters.js
@@ -0,0 +1,15 @@
+const { addCallbackParam } = require("../../helpers");
+const onToggleAPIUpdateList = [
+ "ApplicationLauncher",
+ "BadgeToggle",
+ "DropdownToggle",
+ "KebabToggle",
+ "Toggle",
+ "Select",
+ "SelectToggle",
+];
+// https://github.com/patternfly/patternfly-react/pull/8667
+module.exports = {
+ meta: { fixable: "code" },
+ create: addCallbackParam(onToggleAPIUpdateList, { onToggle: "_event" }),
+};
diff --git a/packages/eslint-plugin-pf-codemods/lib/rules/v5/onToggle-warn-event.js b/packages/eslint-plugin-pf-codemods/lib/rules/v5/onToggle-warn-event.js
deleted file mode 100644
index 8b73f0b73..000000000
--- a/packages/eslint-plugin-pf-codemods/lib/rules/v5/onToggle-warn-event.js
+++ /dev/null
@@ -1,29 +0,0 @@
-const { getPackageImports } = require("../../helpers");
-
-// https://github.com/patternfly/patternfly-react/pull/8667
-module.exports = {
- create: function (context) {
- const onToggleAPIUpdateList = ['ApplicationLauncher', 'BadgeToggle', 'DropdownToggle', 'KebabToggle', 'Toggle', 'Select', 'SelectToggle'];
- const imports = getPackageImports(
- context,
- "@patternfly/react-core"
- ).filter((specifier) => onToggleAPIUpdateList.includes(specifier.imported.name));
-
- return imports.length === 0
- ? {}
- : {
- JSXOpeningElement(node) {
- if (
- imports
- .map((imp) => imp.local.name)
- .includes(node.name.name)
- ) {
- context.report({
- node,
- message: `${node.name.name} onToggle prop has been updated to include the event parameter as its first parameter. onToggle handlers may require an update.`,
- });
- }
- },
- };
- },
-};
diff --git a/packages/eslint-plugin-pf-codemods/test/rules/v5/dataList-updated-callback.js b/packages/eslint-plugin-pf-codemods/test/rules/v5/dataList-updated-callback.js
new file mode 100644
index 000000000..3498e05f7
--- /dev/null
+++ b/packages/eslint-plugin-pf-codemods/test/rules/v5/dataList-updated-callback.js
@@ -0,0 +1,85 @@
+const ruleTester = require("../../ruletester");
+const rule = require("../../../lib/rules/v5/dataList-updated-callback");
+
+ruleTester.run("dataList-updated-callback", rule, {
+ valid: [
+ {
+ code: `import { DataList } from '@patternfly/react-core'; ;`,
+ },
+ {
+ code: `import { DataList } from '@patternfly/react-core';