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

Inconsistent formatting depending on initial state #46

Closed
PymZoR opened this issue Jan 27, 2020 · 1 comment
Closed

Inconsistent formatting depending on initial state #46

PymZoR opened this issue Jan 27, 2020 · 1 comment

Comments

@PymZoR
Copy link

PymZoR commented Jan 27, 2020

I came across those cases (not an exhaustive list though) on files where long lines and big tag attributes were exceeding the maximum line length. While formatting some of them by hand, I figured out that the formatting was actually quite different depending on the initial state.

Prettier version : 1.19.1
Pretter options :

{
  "arrowParens": "avoid",
  "bracketSpacing": true,
  "insertPragma": false,
  "printWidth": 80,
  "proseWrap": "preserve",
  "quoteProps": "as-needed",
  "requirePragma": false,
  "semi": true,
  "singleQuote": false,
  "tabWidth": 2,
  "trailingComma": "none",
  "useTabs": false,
  "parser": "xml"
}

Case 1

Before
<a>
<b>
<c xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="1" yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy="2" zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz="3"/>
</b>
</a>
After
<a>
<b>
<c
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="1"
      yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy="2"
      zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz="3"
    />
</b>
</a>

Here, the b tag is not indented, and the first half of c tag as well as his attributes are missing an indent.

Case 2

Before
<a>
<b>
    <c xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="1" yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy="2" zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz="3"/>
</b>
</a>
After
<a>
<b>
    <c
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="1"
      yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy="2"
      zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz="3"
    />
</b>
</a>

The c tag is correctly indented, b tag still isn't.

Case 3

Before
<a><b><c xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="1" yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy="2" zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz="3"/></b></a>
After
<a><b><c
      xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx="1"
      yyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyy="2"
      zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz="3"
    /></b></a>

I don't really know what is going on on this one.

@kddnewton
Copy link
Member

Yeah this is because in XML, whitespace is sensitive in every element unless otherwise specified by the schema. Try using xmlWhitespaceSensitivity to set "ignore", that's probably what you want.

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

No branches or pull requests

2 participants