Typescript: javascript format: disable insert space inside curly braces

Created on 5 Apr 2017  路  14Comments  路  Source: microsoft/TypeScript

_From @BenjaVR on April 5, 2017 11:13_

Since there are already some javascript.format.insertSpace... settings available in VSCode, I have a suggestion to add another one.

When I import with curly braces, a space is added before and after the "imported word":
image
While doing the same in WebStorm:
image

VSCode also inserts a space to returns:
image

Webstorm does provide a setting for this: "spaces within ES6 import/export braces" to toggle this behaviour. Is it possible to add this setting to VSCode as well?

_Copied from original issue: Microsoft/vscode#23929_

Formatter Suggestion VS Code Tracked help wanted

Most helpful comment

@mzvast it is implemented.

In VS Code, go to preferences (workspace or global), and set
```json
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,

"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
``` There is also an option for[x]`.

All 14 comments

A typescript.format.insertSpace setting would also be most welcome.

Is there any progress about this feature?

@mzvast it is implemented.

In VS Code, go to preferences (workspace or global), and set
```json
"typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,

"javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false,
``` There is also an option for[x]`.

@aluanhaddad I set these two options to false, but auto-import still inserts spaces. These options do not work.
I use VS Code 1.20.0

Just format the document after an import is generated.

@mentapro I had a similar problem and uninstalled some other styling plugins like Prettier. Incidentally, some of the plugins overrides these settings. Unfortunately you have to find it out the hard way by uninstalling plugins and trying again.

@ravsom It's strange, but now I tried these two settings again and they are working fine. I have plugin Beautify and VSCode 1.23.1. Thanks

+1 for getting this issue from an extension in vscode.

esbenp.prettier-vscode replaces vscode's formatting with Prettier transparently, and has the equivalent setting "prettier.bracketSpacing": false.

It works when setting prettier bracketSpacing false

Stupid question: why is VSCode doing all this auto-fix stuff if we have ESLint rules which say it shouldn't? Surely there's a fundamental conflict here?

@cawoodm One question, do you think everybody is using ESLint? And also do you think that there is only one format of code ;-)?

This is awesome feature :).

Hmm... I thought it was a standard - but whatever people use they may see ESLint/TSLint/Whateva highlight code as incorrect which VS Code itself changed to be incorrect. They are fighting each other. If everyone in the team should use the same formatter/prettier then we need this in code (like .eslintrc) and not in everyone's settings.json.

Does someone has fix for this?
In my team some devs are using WebStorm which does not add space in imports, and some devs are using vscode which adds them. This makes a lot of space only changes in pull requests

As noted, I believe this is already handled by the typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces setting in VS Code. I also confirmed that auto import respects this option (no format should be required)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bgrieder picture bgrieder  路  3Comments

weswigham picture weswigham  路  3Comments

kyasbal-1994 picture kyasbal-1994  路  3Comments

jbondc picture jbondc  路  3Comments

zhuravlikjb picture zhuravlikjb  路  3Comments