From 61a071c8e6f0e900819c811b324c6ac09b9103c5 Mon Sep 17 00:00:00 2001 From: Eric Olkowski <70952936+thatblindgeye@users.noreply.github.com> Date: Wed, 10 Jul 2024 16:53:49 -0400 Subject: [PATCH] fix(Popper): updated default of appendTo prop (#688) --- .../src/ruleCustomization.ts | 1 + .../popper-update-appendTo-default.md | 3 + .../popper-update-appendTo-default.test.ts | 103 ++++++++++++++++++ .../popper-update-appendTo-default.ts | 32 ++++++ .../popperUpdateAppendToDefaultInput.tsx | 3 + .../popperUpdateAppendToDefaultOutput.tsx | 3 + 6 files changed, 145 insertions(+) create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.md create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.test.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.ts create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultInput.tsx create mode 100644 packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultOutput.tsx diff --git a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts index 9274ded7e..68d56634b 100644 --- a/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts +++ b/packages/eslint-plugin-pf-codemods/src/ruleCustomization.ts @@ -34,6 +34,7 @@ export const warningRules = [ "overflowMenu-warn-updated-dropdownItem", "pageSection-warn-variantClasses-applied", "popover-warn-appendTo-default", + "popper-update-appendTo-default", "react-dropzone-warn-upgrade", "simpleFileUpload-warn-changes", "sliderStep-warn-update-markup", diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.md b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.md new file mode 100644 index 000000000..bb97b3860 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.md @@ -0,0 +1,3 @@ +### popper-update-appendTo-default [(#10675)](https://github.com/patternfly/patternfly-react/pull/10675) + +The default value of appendTo on Dropdown, Select, and Popper has been updated to `document.body`. diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.test.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.test.ts new file mode 100644 index 000000000..0bc045944 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.test.ts @@ -0,0 +1,103 @@ +const ruleTester = require("../../ruletester"); +import * as rule from "./popper-update-appendTo-default"; + +ruleTester.run("popper-update-appendTo-default", rule, { + valid: [ + { + code: ``, + }, + { + code: `import { Button } from '@patternfly/react-core';`, + }, + ], + invalid: [ + { + code: `import { Dropdown } from '@patternfly/react-core';`, + output: `import { Dropdown } from '@patternfly/react-core';`, + errors: [ + { + message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + { + code: `import { Dropdown as CustomThing } from '@patternfly/react-core';`, + output: `import { Dropdown as CustomThing } from '@patternfly/react-core';`, + errors: [ + { + message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + { + code: `import { Select } from '@patternfly/react-core';`, + output: `import { Select } from '@patternfly/react-core';`, + errors: [ + { + message: `The default value of appendTo on Select has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + { + code: `import { Popper } from '@patternfly/react-core';`, + output: `import { Popper } from '@patternfly/react-core';`, + errors: [ + { + message: `The default value of appendTo on Popper has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + { + code: `import { Dropdown, Select, Popper, Button } from '@patternfly/react-core';`, + output: `import { Dropdown, Select, Popper, Button } from '@patternfly/react-core';`, + errors: [ + { + message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + { + message: `The default value of appendTo on Select has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + { + message: `The default value of appendTo on Popper has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + { + code: `import { Dropdown } from '@patternfly/react-core/dist/esm/components/Dropdown/index.js';`, + output: `import { Dropdown } from '@patternfly/react-core/dist/esm/components/Dropdown/index.js';`, + errors: [ + { + message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + { + code: `import { Dropdown } from '@patternfly/react-core/dist/js/components/Dropdown/index.js';`, + output: `import { Dropdown } from '@patternfly/react-core/dist/js/components/Dropdown/index.js';`, + errors: [ + { + message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + { + code: `import { Dropdown } from '@patternfly/react-core/dist/dynamic/components/Dropdown/index.js';`, + output: `import { Dropdown } from '@patternfly/react-core/dist/dynamic/components/Dropdown/index.js';`, + errors: [ + { + message: `The default value of appendTo on Dropdown has been updated to \`document.body\`.`, + type: "ImportSpecifier", + }, + ], + }, + ], +}); diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.ts b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.ts new file mode 100644 index 000000000..b58c131db --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.ts @@ -0,0 +1,32 @@ +import { Rule } from "eslint"; +import { ImportSpecifier } from "estree-jsx"; +import { getFromPackage } from "../../helpers"; + +// https://github.com/patternfly/patternfly-react/pull/10675 +module.exports = { + meta: {}, + create: function (context: Rule.RuleContext) { + const { imports } = getFromPackage(context, "@patternfly/react-core"); + + const componentImports = imports.filter((specifier) => + ["Dropdown", "Select", "Popper"].includes(specifier.imported.name) + ); + + return !componentImports.length + ? {} + : { + ImportSpecifier(node: ImportSpecifier) { + if ( + componentImports + .map((imp) => imp.imported.name) + .includes(node.imported.name) + ) { + context.report({ + node, + message: `The default value of appendTo on ${node.imported.name} has been updated to \`document.body\`.`, + }); + } + }, + }; + }, +}; diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultInput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultInput.tsx new file mode 100644 index 000000000..4dd3375f2 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultInput.tsx @@ -0,0 +1,3 @@ +import { Dropdown } from "@patternfly/react-core"; + +export const PopperUpdateAppendToDefaultInput = () => \ No newline at end of file diff --git a/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultOutput.tsx b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultOutput.tsx new file mode 100644 index 000000000..4dd3375f2 --- /dev/null +++ b/packages/eslint-plugin-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultOutput.tsx @@ -0,0 +1,3 @@ +import { Dropdown } from "@patternfly/react-core"; + +export const PopperUpdateAppendToDefaultInput = () => \ No newline at end of file