prettier / plugin-xml

Prettier XML plugin
MIT License
231 stars 33 forks source link

not indenting #773

Closed xenoterracide closed 6 months ago

xenoterracide commented 6 months ago

input:

<foo>
  <module name="MethodLength">
    <property name="max" value="25" />
</module>
</foo>

output is the same

expected:

<foo>
  <module name="MethodLength">
    <property name="max" value="25" />
  </module>
</foo>
❯ npx prettier --cache --ignore-unknown --write '**/*.xml'
.config/checkstyle/main.xml 2ms (unchanged) (cached)
.config/checkstyle/t.xml 11ms (unchanged)
.config/checkstyle/test.xml 1ms (unchanged) (cached)
.config/spotbugs/exclude.xml 1ms (unchanged) (cached)
printWidth: 120
plugins:
  - "@prettier/plugin-xml"
  - prettier-plugin-properties
  - prettier-plugin-java
  - prettier-plugin-toml
  - prettier-plugin-sh
.gradle/
node_modules/
build/
.idea/
gradlew*
root = true

[*]
trim_trailing_whitespace = true
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_style = space
indent_size = 2

comment: I simplified it, but my xml files come from checkstyle and spotbugs, so if you want big examples of files they have them.

prettier@3.2.5 dev
node_modules/prettier
  dev prettier@"^3.1.1" from the root project
  prettier@"3.2.5" from prettier-plugin-java@2.6.0
  node_modules/prettier-plugin-java
    dev prettier-plugin-java@"^2.6.0" from the root project
  peer prettier@">= 2.3.0" from prettier-plugin-properties@0.3.0
  node_modules/prettier-plugin-properties
    dev prettier-plugin-properties@"^0.3.0" from the root project
  peer prettier@"^3.0.3" from prettier-plugin-sh@0.14.0
  node_modules/prettier-plugin-sh
    dev prettier-plugin-sh@"^0.14.0" from the root project
  peer prettier@"^3.0.3" from prettier-plugin-toml@2.0.1
  node_modules/prettier-plugin-toml
    dev prettier-plugin-toml@"^2.0.1" from the root project
  peer prettier@"^3.0.0" from @prettier/plugin-xml@3.3.1
  node_modules/@prettier/plugin-xml
    dev @prettier/plugin-xml@"^3.2.2" from the root project
kddnewton commented 6 months ago

Please read https://github.com/prettier/plugin-xml?tab=readme-ov-file#whitespace in the README.

xenoterracide commented 6 months ago

having dealt with xml a lot what ARE you talking about?

https://xml.coverpages.org/rfc-wshp19990416.html

White space serves two distinct purposes. The first is to introduce spaces and line breaks into the element content in a manner that has semantic significance for the XML application, whether this is to separate word and textual parts, to describe visual formatting, or otherwise.

The second is the use of white space to visually format the document in its source form, e.g. when using a text editor to edit an XML file. Such use of white space is purely to assist the reader or editor of the document. This white space is not part of the information conveyed by the document and bears no semantic significance for the XML application.

An XML parser that regards all white space as part of the element content and as conveying information might, with liberally formatted documents, deliver redundant spaces to the application, affecting performance and memory consumption. In addition, the application must employ special code to remove such white space.

the only whitespace xml parsers care about is things like a space to separate the element name from the start of a property... The rest is formatting for human readability.

html can be written as valid xml (or close enough... I think there might be a header difference in html now) https://www.w3.org/blog/2008/html5-is-html-and-xml/ so this plugin should work exactly (but probably simpler because you can whine if it's not well-formed) than the core html functionality.

kddnewton commented 6 months ago

I don't believe that's correct. You can see in the spec:

All of these 3 places indicate that whitespace has semantic meaning. I'm not sure about the RFC you linked — did it get adopted? It's not referenced in the actual spec at all.

Either way, we provide an option for you to ignore semantic whitespace as you see fit. Asking me what I'm talking about is not going to change the default of this library.