Draft
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
This PR adds a new
xmlSelfClosingTagsoption that controls how empty XML tags (tags with no content) are formatted. This provides three formatting modes to accommodate different XML standards and requirements.Motivation
Some XML formats (particularly
.xamlmetadata) require specific tag formatting and do not accept self-closing tags. The current behavior always converts empty tags like<searchLayouts></searchLayouts>to self-closing format<searchLayouts />, which causes issues with version control and IDE workflows when working with these XML formats.This was reported in #793 where users experienced unwanted changes in their VCS that cluttered their IDEs until commits were cleaned with Husky and Prettier.
Changes
The
xmlSelfClosingTagsoption controls how empty XML tags (tags with no content) are formatted. By default ("always"), the plugin will convert all empty tags to self-closing format:If you want to preserve the original formatting from your source files, use
"preserve":If you want to prevent self-closing tags entirely and always use open/close format, use
"never":Interaction with
xmlWhitespaceSensitivityThe
xmlSelfClosingTagsoption works in conjunction with the existingxmlWhitespaceSensitivityoption. Understanding their interaction is important for achieving the desired formatting:With
xmlWhitespaceSensitivity: "strict"(default)When whitespace sensitivity is set to
"strict", XML preserves all whitespace as semantically meaningful. This means:<style> </style>) is not considered emptyxmlSelfClosingTagsoption will not affect tags containing whitespaceWith
xmlWhitespaceSensitivity: "ignore"When whitespace sensitivity is set to
"ignore", whitespace is treated as insignificant. This means:<style> </style>) are treated as emptyxmlSelfClosingTagsoption will affect these tagsxmlSelfClosingTagssettingRecommended Configurations
For most XML files (where whitespace matters):
{ "xmlWhitespaceSensitivity": "strict", "xmlSelfClosingTags": "always" }For Salesforce or XAML metadata (where open/close tags are required):
{ "xmlWhitespaceSensitivity": "ignore", "xmlSelfClosingTags": "never" }For preserving original formatting:
{ "xmlWhitespaceSensitivity": "strict", "xmlSelfClosingTags": "preserve" }Related Issues