56

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>
Pandiyan Cool
  • 6,381
  • 8
  • 51
  • 87
rosiejaneenomar
  • 882
  • 1
  • 10
  • 17

3 Answers3

31

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)

Robert
  • 1,710
  • 2
  • 18
  • 35
  • 5
    This is deprecated as of `4.2.0`. Replaced with `bracketSameLine` – styks Dec 08 '21 at 18:57
  • 4
    I also needed to add htmlWhitespaceSensitivity: ignore in order for it to work. – KTibow Dec 28 '21 at 15:44
  • 1
    @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. – xji Jan 22 '22 at 17:11
  • 1
    worked for me, thanks a lot. mark it to correct answer. – Ali Hajiloo May 27 '22 at 13:28
20

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.

Pandiyan Cool
  • 6,381
  • 8
  • 51
  • 87
  • 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. – rosiejaneenomar Dec 26 '18 at 10:01
  • 36
    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. – Chris Aug 18 '20 at 13:41
  • 3
    @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. – Pandiyan Cool Aug 18 '20 at 13:50
  • 2
    i take "html.format.wrapAttributes": "force-aligned" - nothing has changed, sign ">" transfer, what need check more? – Ярослав Прохоров Oct 18 '20 at 18:36
  • 3
    "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? – Sean Kendle May 13 '21 at 17:35
  • The conclusion of that thread is to avoid using Prettier for HTML: "[We] ignored all file types other than `*.html` using the `beautify.ignore` workspace setting and added `*.html` to `.prettierignore`. So Beautify only formats HTML and Prettier formats everything else." – Merchako Dec 07 '22 at 16:49
  • This isn't helpful. Remember, there are teams who use prettier because it is IDE agnostic. – Rich Jun 30 '23 at 09:24
1

Here is what worked for me for Prettier settings: enter image description here

G Dube
  • 127
  • 7