Skip to content

Commit de88ede

Browse files
committed
Merge pull request #3272 from Microsoft/formattingCloseBracketInFunctionDeclarations
remove space after close bracket only if next token does not start bl…
2 parents cc07865 + f1789ac commit de88ede

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/services/formatting/rules.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ module ts.formatting {
231231
this.NoSpaceBeforeOpenBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
232232
this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
233233
this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
234-
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
234+
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), RuleAction.Delete));
235235

236236
// Place a space before open brace in a function declaration
237237
this.FunctionOpenBraceLeftTokenRange = Shared.TokenRange.AnyIncludingMultilineComments;
@@ -650,6 +650,10 @@ module ts.formatting {
650650
return context.TokensAreOnSameLine();
651651
}
652652

653+
static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean {
654+
return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context)
655+
}
656+
653657
static IsEndOfDecoratorContextOnSameLine(context: FormattingContext): boolean {
654658
return context.TokensAreOnSameLine() &&
655659
context.contextNode.decorators &&
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path="fourslash.ts"/>
2+
3+
/////*0*/function listAPIFiles(path: string): string[] {/*1*/ }
4+
5+
goTo.marker("1");
6+
edit.insertLine("");
7+
goTo.marker("0");
8+
verify.currentLineContentIs("function listAPIFiles(path: string): string[] {");

0 commit comments

Comments
 (0)