I don't know if this is the default behavior for VS Code, (I have a lot of custom config on top of the default)
But when I format the code, it transforms such code:
const simpleInput = (
<Input
{...input}
{...others}
state={state}
/>
);
Into :
const simpleInput = (
<Input
{...input}
{...others}
state={state}
/> <- Here is the difference
);
And my es-lint throw a warning about it [eslint] The closing bracket must be aligned with the line containing the opening tag (expected column 5) (react/jsx-closing-bracket-location)
How can I tweak it so it aligns properly with the tag start?
Note than the file is using JSX
in a .js file, I configured VS code accordingly.
You can use the Rename Symbol command to do this. Opening and closing tags will both be renamed. Alternatively, you can press Shift + Enter at step 3 to preview changes and then Shift + Enter again to apply them.
You can use hot key Ctrl+M (Command+M) to beautify your JSX file.
VSCode uses https://github.com/Microsoft/TypeScript underneath for auto formatting.
There is a recently closed issue in TypeScript repo for the same problem you have: https://github.com/Microsoft/TypeScript/issues/8663
The changes have not been reflected to VSCode Stable version yet, but with current version of VSCode Insiders (https://code.visualstudio.com/insiders) it tag-aligns the closing bracket.
You can download and use VSCode Insiders or change your eslint rule to use props-aligned brackets until it makes to the stable release:
"react/jsx-closing-bracket-location": [
"warning",
"props-aligned"
],
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With