Skip to content

Add xmlSelfClosingTags option to disable auto-self-closing empty elements#993

Open
fuleinist wants to merge 1 commit intoprettier:mainfrom
fuleinist:add-xml-self-closing-option
Open

Add xmlSelfClosingTags option to disable auto-self-closing empty elements#993
fuleinist wants to merge 1 commit intoprettier:mainfrom
fuleinist:add-xml-self-closing-option

Conversation

@fuleinist
Copy link
Copy Markdown

Summary

Adds a new option xmlSelfClosingTags (default: true) that controls whether empty elements are rendered as <tag/> or <tag></tag>.

Problem

Some XML formats (notably Salesforce metadata) should not use self-closing syntax:

<searchLayouts></searchLayouts>

But prettier-plugin-xml currently auto-converts this to:

<searchLayouts />

This causes unnecessary VCS diffs and clutter in IDEs until commits are cleaned with Husky.

Solution

When xmlSelfClosingTags: false, empty elements preserve explicit open/close tags:

<searchLayouts></searchLayouts>

Usage

{
  "xmlSelfClosingTags": false
}

Or via CLI: --xml-self-closing-tags=false

Implementation

  • Added xmlSelfClosingTags option in plugin.js with default true
  • Modified printer.js to check this option when rendering empty elements
  • Maintains backward compatibility (existing behavior unchanged by default)
  • All existing tests pass

Fixes: #793

…ents

Adds a new option xmlSelfClosingTags (default: true) that controls whether
empty elements are rendered as <tag/> or <tag></tag>.

When set to false, empty elements preserve explicit open/close tags,
which is useful for Salesforce metadata and other XML formats where
self-closing syntax causes unwanted VCS diffs.

Fixes: prettier#793
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.

Please include option not to auto-self-close empty nodes

1 participant