diff --git a/generate.js b/generate.js index c78c3800a..e891d35b8 100644 --- a/generate.js +++ b/generate.js @@ -69,12 +69,3 @@ ruleTester.run("${newRuleName}", rule, { }); ` ); - -// Update index file -const ruleIndexPath = path.join(__dirname, 'packages/eslint-plugin-pf-codemods/index.js'); -const ruleIndex = fs.readFileSync(ruleIndexPath, 'utf8'); -fs.writeFileSync( - ruleIndexPath, - // (ab)Use fact that `rules` object is at top of file - ruleIndex.replace("};", ` "${newRuleName}": require('./lib/rules/v5/${newRuleName}'),\n};`) -); diff --git a/packages/eslint-plugin-pf-codemods/index.js b/packages/eslint-plugin-pf-codemods/index.js index 812dc02c8..239cd877a 100644 --- a/packages/eslint-plugin-pf-codemods/index.js +++ b/packages/eslint-plugin-pf-codemods/index.js @@ -11,7 +11,7 @@ const v5rules = createListOfRules("5"); const v4rules = createListOfRules("4"); // if you want a rule to have a severity that defaults to warning rather than error, add the rule name to the below array -const warningRules = ["applicationLauncher-warn-input", "horizontalSubnav-ariaLabel", "wizard-warn-button-order"] +const warningRules = ["applicationLauncher-warn-input", "horizontalSubnav-ariaLabel", "tabs-warn-children-type-changed", "wizard-warn-button-order"] const createRules = (rules) => { return Object.keys(rules).reduce((acc, rule) => { diff --git a/packages/eslint-plugin-pf-codemods/lib/rules/v5/tabs-warn-children-type-changed.js b/packages/eslint-plugin-pf-codemods/lib/rules/v5/tabs-warn-children-type-changed.js new file mode 100644 index 000000000..384301773 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/lib/rules/v5/tabs-warn-children-type-changed.js @@ -0,0 +1,21 @@ +// https://github.com/patternfly/patternfly-react/pull/8217 +module.exports = { + create: function (context) { + return { + ImportDeclaration(node) { + const TabsImport = node.specifiers.find( + (specifier) => + specifier.imported.name === "Tabs" && + node.source.value === "@patternfly/react-core" + ); + + if (TabsImport) { + context.report({ + node, + message: "The children of the 'Tabs' component must now be passed a 'Tab' component or a falsy value.", + }); + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/test/rules/v5/tabs-warn-children-type-changed.js b/packages/eslint-plugin-pf-codemods/test/rules/v5/tabs-warn-children-type-changed.js new file mode 100644 index 000000000..6af2c35a7 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/test/rules/v5/tabs-warn-children-type-changed.js @@ -0,0 +1,20 @@ +const ruleTester = require('../../ruletester'); +const rule = require('../../../lib/rules/v5/tabs-warn-children-type-changed'); + +ruleTester.run("tabs-warn-children-type-changed", rule, { + valid: [ + { + code: `Child`, + } + ], + invalid: [ + { + code: `import { Tabs } from '@patternfly/react-core';`, + output: `import { Tabs } from '@patternfly/react-core';`, + errors: [{ + message: `The children of the 'Tabs' component must now be passed a 'Tab' component or a falsy value.`, + type: "ImportDeclaration", + }] + }, + ] +}); diff --git a/packages/pf-codemods/README.md b/packages/pf-codemods/README.md index d0af54c3d..4242ab4a7 100644 --- a/packages/pf-codemods/README.md +++ b/packages/pf-codemods/README.md @@ -502,6 +502,12 @@ Out: ``` +### tabs-warn-children-type-changed [(#8217)](https://github.com/patternfly/patternfly-react/pull/8217) + +We've restricted the type of elements that can be passed to the `Tabs` component. + +This rule will raise a warning when `Tabs` is imported in a file, even if the children passed to it are already of the appropriate type. It will not make any code changes. + ### toggle-remove-isprimary [(#8179)](https://github.com/patternfly/patternfly-react/pull/8179) We've removed the deprecated `isPrimary` prop. This rule wil replace it with the "primary" value on the `toggleVariant` prop. diff --git a/test/test.tsx b/test/test.tsx index a2f7c7660..6a4584ea8 100644 --- a/test/test.tsx +++ b/test/test.tsx @@ -2,6 +2,7 @@ import { AccordionExpandableContent } from "@patternfly/react-core"; import { ApplicationLauncher } from "@patternfly/react-core"; import { KEY_CODES } from "@patternfly/react-core"; import { Nav } from "@patternfly/react-core"; +import { Tabs } from "@patternfly/react-core"; import { Wizard } from "@patternfly/react-core"; import { WizardFooter } from "@patternfly/react-core/next";