-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Popper): updated default of appendTo prop (#688)
- Loading branch information
1 parent
9ee53c9
commit 61a071c
Showing
6 changed files
with
145 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...mods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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`. |
103 changes: 103 additions & 0 deletions
103
...-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: `<Dropdown appendTo />`, | ||
}, | ||
{ | ||
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", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
32 changes: 32 additions & 0 deletions
32
...in-pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popper-update-appendTo-default.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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\`.`, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
3 changes: 3 additions & 0 deletions
3
...pf-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultInput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Dropdown } from "@patternfly/react-core"; | ||
|
||
export const PopperUpdateAppendToDefaultInput = () => <Dropdown appendTo /> |
3 changes: 3 additions & 0 deletions
3
...f-codemods/src/rules/v6/popperUpdateAppendToDefault/popperUpdateAppendToDefaultOutput.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import { Dropdown } from "@patternfly/react-core"; | ||
|
||
export const PopperUpdateAppendToDefaultInput = () => <Dropdown appendTo /> |