How to disable prettier settings creating new line of > of html tag?

30,235

Solution 1

This can be done with help of VS Code itself. Place the following entry in your workspace settings in your vs code.

"html.format.wrapAttributes": "force-aligned"

You don't need any external plugins or extension to do this.

Or you can use the GUI settings page as well

enter image description here

enter image description here

UPDATE 01

Based on github issue in prettier repo https://github.com/prettier/prettier-vscode/issues/646

you can still merge the settings I have mentioned above.

Solution 2

For JSX (and other file types, like HTML) this can be done setting

"bracketSameLine": true

in your .prettierrc

see https://prettier.io/docs/en/options.html#bracket-line

(or jsxBracketSameLine for versions < 4.2.0)

Share:
30,235
rosiejaneenomar
Author by

rosiejaneenomar

Updated on July 09, 2022

Comments

  • rosiejaneenomar
    rosiejaneenomar almost 2 years

    I walk through the Prettier extension of Vscode and I can't find how to disable this scenario. See the > of html tag.

    Here's a sample code that needed some fix, every time i run the Prettier. The output is this:

    <tag-html
     [val1]="valueStr"
     [val2]="valueStr"
    >
    </tag-html>
    

    I want Prettier to output:

    <tag-html
     [val1]="valueStr"
     [val2]="valueStr">
    </tag-html>
    
  • rosiejaneenomar
    rosiejaneenomar over 5 years
    hi, thank you for the answer, I worked when not using prettier, but I need the extension as it is being used already on the project.
  • Chris
    Chris almost 4 years
    This is a poor answer as it doesn't address the question. I came here from Google looking for the prettier solution as I don't use VS Code.
  • Pandiyan Cool
    Pandiyan Cool almost 4 years
    @ChrisTurner It might not answer your question. But answered the real question, and question-asker accepted the answer at that time (2018). If you really have any specific questions, please raise - happy to answer if possible.
  • Ярослав Прохоров
    Ярослав Прохоров over 3 years
    i take "html.format.wrapAttributes": "force-aligned" - nothing has changed, sign ">" transfer, what need check more?
  • Sean Kendle
    Sean Kendle about 3 years
    "you can still merge the settings" - you linked to a very, very long thread that I don't have time to read. How can you merge settings? I just tried setting that setting, and it changes nothing. Merge how?
  • styks
    styks over 2 years
    This is deprecated as of 4.2.0. Replaced with bracketSameLine
  • KTibow
    KTibow over 2 years
    I also needed to add htmlWhitespaceSensitivity: ignore in order for it to work.
  • xji
    xji over 2 years
    @styks Your answer helped my project work again. I think older versions of React Native new project templates still use the old jsxBracketSameLine key and it therefore stopped working after I updated my Prettier. IMO they should have deprecated it but not removed it.
  • Ali Hajiloo
    Ali Hajiloo about 2 years
    worked for me, thanks a lot. mark it to correct answer.