Skip to content

Commit 14b3949

Browse files
Merge pull request #6394 from SaschaNaz/noSpaceBetweenCommaAndCB
Remove space between comma and close bracket
2 parents a444be8 + 5431e09 commit 14b3949

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

src/services/formatting/rules.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,7 @@ namespace ts.formatting {
444444
///
445445

446446
// Insert space after comma delimiter
447-
this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
447+
this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space));
448448
this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
449449

450450
// Insert space before and after binary operators
@@ -711,6 +711,10 @@ namespace ts.formatting {
711711
return context.currentTokenSpan.kind !== SyntaxKind.CommaToken;
712712
}
713713

714+
static IsNextTokenNotCloseBracket(context: FormattingContext): boolean {
715+
return context.nextTokenSpan.kind !== SyntaxKind.CloseBracketToken;
716+
}
717+
714718
static IsArrowFunctionContext(context: FormattingContext): boolean {
715719
return context.contextNode.kind === SyntaxKind.ArrowFunction;
716720
}

tests/cases/fourslash/formattingOptionsChange.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
///<reference path="fourslash.ts"/>
22

3-
/////*InsertSpaceAfterCommaDelimiter*/[1,2, 3];
3+
/////*InsertSpaceAfterCommaDelimiter*/[1,2, 3];[ 72 , ];
44
/////*InsertSpaceAfterSemicolonInForStatements*/for (i = 0;i; i++);
55
/////*InsertSpaceBeforeAndAfterBinaryOperators*/1+2- 3
66
/////*InsertSpaceAfterKeywordsInControlFlowStatements*/if (true) { }
@@ -13,13 +13,13 @@
1313
/////*PlaceOpenBraceOnNewLineForControlBlocks*/if (true) {
1414
////}
1515

16-
runTest("InsertSpaceAfterCommaDelimiter", "[1, 2, 3];", "[1,2,3];");
16+
runTest("InsertSpaceAfterCommaDelimiter", "[1, 2, 3];[72,];", "[1,2,3];[72,];");
1717
runTest("InsertSpaceAfterSemicolonInForStatements", "for (i = 0; i; i++);", "for (i = 0;i;i++);");
1818
runTest("InsertSpaceBeforeAndAfterBinaryOperators", "1 + 2 - 3", "1+2-3");
1919
runTest("InsertSpaceAfterKeywordsInControlFlowStatements", "if (true) { }", "if(true) { }");
2020
runTest("InsertSpaceAfterFunctionKeywordForAnonymousFunctions", "(function () { })", "(function() { })");
2121
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", " ( 1 )", " (1)");
22-
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets", "[ 1 ];[];[];[ , ];", "[1];[];[];[, ];");
22+
runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets", "[ 1 ];[];[];[ , ];", "[1];[];[];[,];");
2323
runTest("InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", "`${ 1 }`; `${ 1 }`", "`${1}`; `${1}`");
2424
runTest("PlaceOpenBraceOnNewLineForFunctions", "class foo", "class foo {");
2525
runTest("PlaceOpenBraceOnNewLineForControlBlocks", "if ( true )", "if ( true ) {");

0 commit comments

Comments
 (0)