Nikita Shchypyplov
Nikita Shchypyplov

Reputation: 1160

How to prevent VS Code from adding space before self-closing JSX tag?

I have this issue for a while. We have ESlint and it forbids us to add space before self-closing JSX-tag, but when I format .jsx file within VS Code it inserts it. How may I disable it?

There is screenshot with the problem:

enter image description here

Thanks!

Upvotes: 13

Views: 3925

Answers (3)

JKL
JKL

Reputation: 1

In VS Code Settings search for "prettier" Default Formatter and change it to Prettier ESLint (maybe you will need to install it i dont remember)

and checkout for eslint rule "react/jsx-tag-spacing"

check out screenshot

Upvotes: 0

Debashis Chowdhury
Debashis Chowdhury

Reputation: 614

Use language mode javascriptreact, instead of javascript

enter image description here

Upvotes: 0

Jan P
Jan P

Reputation: 866

To my knowledge there is no such formatting option within the javascript.format options. But you can always look into extensions for this kind of job.

A lot of people use Prettier these days, but it is opinionated and there is no guarantee it will work well with all your ESLint options. It has an ESLint integrationn though, so maybe you want to have a look at this.

You can also have a look at react-beautify, which seems to have an option for this. But I am not familiar with this extension.

Upvotes: 2

Related Questions