Skip to content
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(buttonMoveIconsIconProp rule): transform to self closing tag #728

Merged
merged 1 commit into from
Aug 28, 2024

Conversation

adamviktora
Copy link
Contributor

@adamviktora adamviktora commented Jul 31, 2024

Closes #694

Also supports Icon / react-icons being used in children attribute.

Copy link
Collaborator

@wise-king-sullyman wise-king-sullyman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great! One non-blocking thought.

Comment on lines 91 to 133
if (node.closingElement) {
const closingSymbol = context
.getSourceCode()
.getLastToken(node.openingElement)!;

fixes.push(
fixer.replaceText(closingSymbol, " />"),
fixer.remove(node.closingElement)
);
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Think it would be worth helperizing this? Seems like something that would be useful in a lot of situations.

Though if we do helperize it we should probably add a check to only make an element self closing if it doesn't have any children.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added the helper.

About checking that element has no children - this was problematic, because for example in this button rule, we remove the children in a fix and at the same time this fix for removing closing element is applied (so the node still has children at the time the condition is checked). We would have to run the self-closing fix additionaly in a cleanup rule.

So I made the helper customizable where it is not allowed to remove children by default, but it can be overwritten.

Copy link
Collaborator

@thatblindgeye thatblindgeye left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than the above lgtm

@adamviktora
Copy link
Contributor Author

We should wait with merging #735 first. There will be conflicts and the helper will need updates, because we cannot remove all children content in case of non plain Buttons.

- also fixes Icon imported with alias
- supports Icon / react-icons being used in children attribute
@thatblindgeye thatblindgeye merged commit 57090b5 into patternfly:main Aug 28, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

buttonMoveIconsIconProp rule: transform to self closing tag
3 participants