-
Notifications
You must be signed in to change notification settings - Fork 20
feat(Select,Dropdown): renamed itemId prop #493
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
packages/eslint-plugin-pf-codemods/lib/rules/v5/selectDropdown-rename-itemId.js
This file contains hidden or 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,39 @@ | ||
| const { getFromPackage, renamePropsOnNode } = require("../../helpers"); | ||
| const renames = { | ||
| SelectOption: { | ||
| itemId: { | ||
| newName: "value", | ||
| message: (node) => | ||
| `itemId prop for ${node?.name?.name} has been renamed to value`, | ||
| }, | ||
| }, | ||
| DropdownItem: { | ||
| itemId: { | ||
| newName: "value", | ||
| message: (node) => | ||
| `itemId prop for ${node?.name?.name} has been renamed to value`, | ||
| }, | ||
| }, | ||
| }; | ||
|
|
||
| // https://github.com/patternfly/patternfly-react/pull/9175 | ||
| module.exports = { | ||
| meta: { fixable: "code" }, | ||
| create: function (context) { | ||
| const { imports: coreImports } = getFromPackage( | ||
| context, | ||
| "@patternfly/react-core" | ||
| ); | ||
| const selectAndDropdownImports = coreImports.filter((imp) => | ||
| ["SelectOption", "DropdownItem"].includes(imp.imported?.name) | ||
| ); | ||
|
|
||
| return !selectAndDropdownImports.length | ||
| ? {} | ||
| : { | ||
| JSXOpeningElement(node) { | ||
| renamePropsOnNode(context, selectAndDropdownImports, node, renames); | ||
| }, | ||
| }; | ||
| }, | ||
| }; |
91 changes: 91 additions & 0 deletions
91
packages/eslint-plugin-pf-codemods/test/rules/v5/selectDropdown-rename-itemId.js
This file contains hidden or 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,91 @@ | ||
| const ruleTester = require("../../ruletester"); | ||
| const rule = require("../../../lib/rules/v5/selectDropdown-rename-itemId"); | ||
|
|
||
| ruleTester.run("selectDropdown-rename-itemId", rule, { | ||
| valid: [ | ||
| { | ||
| code: `import { SelectOption } from '@patternfly/react-core'; <SelectOption />`, | ||
| }, | ||
| { | ||
| code: `import { SelectOption } from '@patternfly/react-core'; <SelectOption value />`, | ||
| }, | ||
| { | ||
| code: `import { DropdownItem } from '@patternfly/react-core'; <DropdownItem />`, | ||
| }, | ||
| { | ||
| code: `import { DropdownItem } from '@patternfly/react-core'; <DropdownItem value />`, | ||
| }, | ||
| { | ||
| // No @patternfly/react-core import | ||
| code: `<SelectOption itemId />`, | ||
| }, | ||
| { | ||
| // No @patternfly/react-core import | ||
| code: `<DropdownItem itemId />`, | ||
| }, | ||
| ], | ||
| invalid: [ | ||
| { | ||
| code: `import { SelectOption } from '@patternfly/react-core'; <SelectOption itemId="test" />`, | ||
| output: `import { SelectOption } from '@patternfly/react-core'; <SelectOption value="test" />`, | ||
| errors: [ | ||
| { | ||
| message: `itemId prop for SelectOption has been renamed to value`, | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: `import { DropdownItem } from '@patternfly/react-core'; <DropdownItem itemId="test" />`, | ||
| output: `import { DropdownItem } from '@patternfly/react-core'; <DropdownItem value="test" />`, | ||
| errors: [ | ||
| { | ||
| message: `itemId prop for DropdownItem has been renamed to value`, | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Import from dist | ||
| { | ||
| code: `import { SelectOption } from '@patternfly/react-core/dist/esm/components/Select/index.js'; <SelectOption itemId="test" />`, | ||
| output: `import { SelectOption } from '@patternfly/react-core/dist/esm/components/Select/index.js'; <SelectOption value="test" />`, | ||
| errors: [ | ||
| { | ||
| message: `itemId prop for SelectOption has been renamed to value`, | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: `import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/index.js'; <DropdownItem itemId="test" />`, | ||
| output: `import { DropdownItem } from '@patternfly/react-core/dist/esm/components/Dropdown/index.js'; <DropdownItem value="test" />`, | ||
| errors: [ | ||
| { | ||
| message: `itemId prop for DropdownItem has been renamed to value`, | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| // Aliased import | ||
| { | ||
| code: `import { SelectOption as PFSO } from '@patternfly/react-core'; <PFSO itemId="test" />`, | ||
| output: `import { SelectOption as PFSO } from '@patternfly/react-core'; <PFSO value="test" />`, | ||
| errors: [ | ||
| { | ||
| message: `itemId prop for PFSO has been renamed to value`, | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| { | ||
| code: `import { DropdownItem as PFDI } from '@patternfly/react-core'; <PFDI itemId="test" />`, | ||
| output: `import { DropdownItem as PFDI } from '@patternfly/react-core'; <PFDI value="test" />`, | ||
| errors: [ | ||
| { | ||
| message: `itemId prop for PFDI has been renamed to value`, | ||
| type: "JSXOpeningElement", | ||
| }, | ||
| ], | ||
| }, | ||
| ], | ||
| }); | ||
This file contains hidden or 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
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a big deal but /next for valid tests too? not sure that
someProptest has much value alongsidevalueThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the react next logic since it may not be necessary