-
Notifications
You must be signed in to change notification settings - Fork 19
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
feat(Label): replace isOverflowLabel with variant="overflow" #580
Merged
wise-king-sullyman
merged 5 commits into
patternfly:main
from
adamviktora:label_remove_isOverflowLabel
Feb 27, 2024
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
0619d4e
feat(Label): replace isOverflowLabel with variant="overflow"
adamviktora 8b54fd9
fix(Label): remove existing variant prop if isOverflowLabel was present
adamviktora 91b73b5
update types
adamviktora e951fff
add type to fixer
adamviktora 662a2c3
refactor(Label): early return
adamviktora 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
17 changes: 17 additions & 0 deletions
17
...odemods/src/rules/v6/labelRemoveIsOverflowLabel/label-remove-isOverflowLabel.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,17 @@ | ||
### label-remove-isOverflowLabel [(#10037)](https://github.com/patternfly/patternfly-react/pull/10037) | ||
|
||
The `isOverflowLabel` prop for Label has been replaced with `variant="overflow"`. Running the fix for this rule will replace an existing `variant` prop (which had no effect if `isOverflowLabel` was used). | ||
|
||
#### Examples | ||
|
||
In: | ||
|
||
```jsx | ||
%inputExample% | ||
``` | ||
|
||
Out: | ||
|
||
```jsx | ||
%outputExample% | ||
``` |
37 changes: 37 additions & 0 deletions
37
...-pf-codemods/src/rules/v6/labelRemoveIsOverflowLabel/label-remove-isOverflowLabel.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,37 @@ | ||
const ruleTester = require("../../ruletester"); | ||
import * as rule from "./label-remove-isOverflowLabel"; | ||
|
||
ruleTester.run("label-remove-isOverflowLabel", rule, { | ||
valid: [ | ||
{ | ||
code: `<Label isOverflowLabel />`, | ||
}, | ||
{ | ||
code: `import { Label } from '@patternfly/react-core'; <Label someOtherProp />`, | ||
}, | ||
], | ||
invalid: [ | ||
{ | ||
code: `import { Label } from '@patternfly/react-core'; <Label isOverflowLabel />`, | ||
output: `import { Label } from '@patternfly/react-core'; <Label variant="overflow" />`, | ||
errors: [ | ||
{ | ||
message: | ||
'The `isOverflowLabel` prop for Label has been replaced with `variant="overflow"`.', | ||
type: "JSXOpeningElement", | ||
}, | ||
], | ||
}, | ||
{ | ||
code: `import { Label } from '@patternfly/react-core'; <Label isOverflowLabel variant="outline" />`, | ||
output: `import { Label } from '@patternfly/react-core'; <Label variant="overflow" />`, | ||
errors: [ | ||
{ | ||
message: | ||
'The `isOverflowLabel` prop for Label has been replaced with `variant="overflow"`. Running the fix for this rule will replace an existing `variant` prop (which had no effect if `isOverflowLabel` was used).', | ||
type: "JSXOpeningElement", | ||
}, | ||
], | ||
}, | ||
], | ||
}); |
65 changes: 65 additions & 0 deletions
65
...lugin-pf-codemods/src/rules/v6/labelRemoveIsOverflowLabel/label-remove-isOverflowLabel.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,65 @@ | ||
import { getFromPackage } from "../../helpers"; | ||
import { Rule } from "eslint"; | ||
import { JSXOpeningElement } from "estree-jsx"; | ||
|
||
// https://github.com/patternfly/patternfly-react/pull/10037 | ||
module.exports = { | ||
meta: { fixable: "code" }, | ||
create: function (context: Rule.RuleContext) { | ||
const { imports } = getFromPackage(context, "@patternfly/react-core"); | ||
|
||
const labelImport = imports.find( | ||
(specifier: { imported: { name: string } }) => | ||
specifier.imported.name === "Label" | ||
); | ||
|
||
return !labelImport | ||
? {} | ||
: { | ||
JSXOpeningElement(node: JSXOpeningElement) { | ||
if ( | ||
node.name.type === "JSXIdentifier" && | ||
labelImport.local.name === node.name.name | ||
) { | ||
const isOverflowLabelAttribute = node.attributes.find( | ||
(attr) => | ||
attr.type === "JSXAttribute" && | ||
attr.name?.name === "isOverflowLabel" | ||
); | ||
|
||
if (isOverflowLabelAttribute === undefined) { | ||
return; | ||
} | ||
|
||
const variantAttribute = node.attributes.find( | ||
(attr) => | ||
attr.type === "JSXAttribute" && attr.name?.name === "variant" | ||
); | ||
|
||
const baseMessage = | ||
'The `isOverflowLabel` prop for Label has been replaced with `variant="overflow"`.'; | ||
|
||
context.report({ | ||
node, | ||
message: variantAttribute | ||
? `${baseMessage} Running the fix for this rule will replace an existing \`variant\` prop (which had no effect if \`isOverflowLabel\` was used).` | ||
: baseMessage, | ||
fix: <Rule.ReportFixer>function (fixer) { | ||
const fixes = [ | ||
fixer.replaceText( | ||
isOverflowLabelAttribute, | ||
'variant="overflow"' | ||
), | ||
]; | ||
if (variantAttribute) { | ||
fixes.push(fixer.remove(variantAttribute)); | ||
} | ||
|
||
return fixes; | ||
}, | ||
}); | ||
} | ||
}, | ||
}; | ||
}, | ||
}; |
6 changes: 6 additions & 0 deletions
6
...n-pf-codemods/src/rules/v6/labelRemoveIsOverflowLabel/labelRemoveIsOverflowLabelInput.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,6 @@ | ||
import { Label } from "@patternfly/react-core"; | ||
|
||
export const LabelRemoveIsOverflowLabelInput = () => <Label isOverflowLabel />; | ||
export const LabelRemoveIsOverflowLabelInput2 = () => ( | ||
<Label isOverflowLabel variant="outline" /> | ||
); |
8 changes: 8 additions & 0 deletions
8
...-pf-codemods/src/rules/v6/labelRemoveIsOverflowLabel/labelRemoveIsOverflowLabelOutput.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,8 @@ | ||
import { Label } from "@patternfly/react-core"; | ||
|
||
export const LabelRemoveIsOverflowLabelInput = () => ( | ||
<Label variant="overflow" /> | ||
); | ||
export const LabelRemoveIsOverflowLabelInput2 = () => ( | ||
<Label variant="overflow" /> | ||
); |
Oops, something went wrong.
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.
This will require an update to be made either to the renameProps helper or this rule to be more custom, but we should add an invalid test that checks whether an existing
variant
prop is replaced or not:I'd be fine having this be a followup, though, especially since we can't be sure if consumers would be passing both isOverflowLabel and a variant (since the variant shouldn't have any effect for an overflow label I believe).
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.
Good point! I think we can do the change right now, I will make this rule more custom