You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
New option to remove spaces around braces: insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces #9613
changed the title [-]Visual studio adding extra spaces on function shorthands[/-][+]New option to remove spaces around braces: insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces[/+]on Dec 16, 2016
Braces are not brackets and any new settings for this situation is not implemented yet. I'm not sure what should exactly be done there, will people want to incorporate rules for objects var a = {} and interfaces interface A { }?
Personally I do want to incorporate them and I really don't want to make two different rules to apply on those two different cases.
(The decision is not a super major factor for the delay, it's just that I had no time to visit here for months)
I think that majority of TypeScript projects use default format settings provided by TLS. At the same time JS guys use lots of different formatters, so I think this settings should influence JavaScript built-ins. There may be two settings. one for structuring objects
We already have two different options specific for template strings (`${x}` vs `${ x }`) and JSX expressions (<foo bar={x} /> vs <foo bar={ x } />) so I think it may be too much to add another multiple options including insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesForGeneralCase (what general?) and insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesForFunctionAndClasses.
BTW, I think the new title is wrong as OP said about "empty" braces rather than nonempty braces. Mohamed Hegazy (@mhegazy)
let's say we have InsertSpaceAfterOpeningAndBeforeClosingDestructuringBracesAndBrackets (could find a better name). this way at least, var [a,b] will be have the same as var {a, b}. and then we are left of with the [a,b] being different from {a,b} as we are today.
We have not heard about this as a complain though, but if users ask for it, we can add insertSpaceInEmptyObjectLiteral and insertSpaceInEmptyArrayLiteral. i do not think this applies to template string, destructing patterns, imports, or JSX though, since you would not specify empty list in any of these.
typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: false is the only option at the moment, but I would prefer multiple options to make code look like:
Activity
dbaeumer commentedon Jul 11, 2016
Moving to TS team since the formatter comes from the tsserver.
mhegazy commentedon Jul 11, 2016
This should be controled by
insertSpaceAfterOpeningAndBeforeClosingNonemptyBracketsbut looks like it is not being honored.saschanaz commentedon Jul 31, 2016
I think
insertSpaceAfterOpeningAndBeforeClosingNonemptyBracketsis for 'brackets'.https://github.com/Microsoft/TypeScript/blob/730f18955dc17068be33691f0fb0e0285ebbf9f5/tests/cases/fourslash/formattingOptionsChange.ts#L22 :
Maybe a new option for braces is needed?
PS: Will the option finally make brace formatting rule consistent?
aymone commentedon Aug 2, 2016
+1 New option for braces...
[-]Visual studio adding extra spaces on function shorthands[/-][+]New option to remove spaces around braces: insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces[/+]alexanderby commentedon Dec 21, 2016
So, I'm using VSCode 1.8.1, I have the next workspace settings
{ "javascript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets": false }Still instead of
I get this
Is this issue fixed?
saschanaz commentedon Dec 21, 2016
Braces are not brackets and any new settings for this situation is not implemented yet. I'm not sure what should exactly be done there, will people want to incorporate rules for objects
var a = {}and interfacesinterface A { }?Personally I do want to incorporate them and I really don't want to make two different rules to apply on those two different cases.
(The decision is not a super major factor for the delay, it's just that I had no time to visit here for months)
alexanderby commentedon Dec 21, 2016
I think that majority of TypeScript projects use default format settings provided by TLS. At the same time JS guys use lots of different formatters, so I think this settings should influence JavaScript built-ins. There may be two settings. one for structuring objects
and another one for functions and classes
saschanaz commentedon Dec 21, 2016
We already have two different options specific for template strings (
`${x}`vs`${ x }`) and JSX expressions (<foo bar={x} />vs<foo bar={ x } />) so I think it may be too much to add another multiple options includinginsertSpaceAfterOpeningAndBeforeClosingNonemptyBracesForGeneralCase(what general?) andinsertSpaceAfterOpeningAndBeforeClosingNonemptyBracesForFunctionAndClasses.BTW, I think the new title is wrong as OP said about "empty" braces rather than nonempty braces. Mohamed Hegazy (@mhegazy)
saschanaz commentedon Dec 21, 2016
What does TS team think about this?
9 remaining items
mhegazy commentedon Dec 22, 2016
:D
mhegazy commentedon Dec 22, 2016
let's say we have
InsertSpaceAfterOpeningAndBeforeClosingDestructuringBracesAndBrackets(could find a better name). this way at least,var [a,b]will be have the same asvar {a, b}. and then we are left of with the[a,b]being different from{a,b}as we are today.dumplings commentedon Apr 17, 2017
i wanna format
to
but
all doesn't work. how could i do?
jibbers42 commentedon Jun 9, 2017
Can someone edit the title to reflect the example given by the OP? I think Mohamed Hegazy (@mhegazy) had a good suggestion (#9613 (comment))
takahser commentedon Mar 7, 2018
@chandler0415 this worked for me:
(you might want to set them to
falsein your case)editor: VS Code 1.20.1
alexanderby commentedon Mar 7, 2018
typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces: falseis the only option at the moment, but I would prefer multiple options to make code look like:So, I would prefer having no space inside objects, arrays and destructurings, but having space inside functions, interfaces, scopes.
fochkun commentedon Apr 14, 2020
when i use "typescript.format.insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces": false
on this
I expect vscode to not change anything, but got this
How can I turn of this rule?
silverwind commentedon Mar 15, 2024
The insertion of spaces during
importautocompletion is very annoying, e.g. typeimport item<tab>, result is:Both the
insertSpaceAfterOpeningAndBeforeClosingNonemptyBracesandinsertSpaceAfterOpeningAndBeforeClosingEmptyBracesoptions have no effect.PS: Should this issue be moved to the VSCode repo?
silverwind commentedon Mar 15, 2024
Reported the
import issuein VSCode repo at #57834RyanCavanaugh commentedon Dec 3, 2025
Closing language service bugs related to the 6.0 implementation. For more information, see #62827