Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/services/formatting/rules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ module ts.formatting {
this.NoSpaceBeforeOpenBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterOpenBracket = new Rule(RuleDescriptor.create3(SyntaxKind.OpenBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceBeforeCloseBracket = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CloseBracketToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
this.NoSpaceAfterCloseBracket = new Rule(RuleDescriptor.create3(SyntaxKind.CloseBracketToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNotBeforeBlockInFunctionDeclarationContext), RuleAction.Delete));

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

static IsNotBeforeBlockInFunctionDeclarationContext(context: FormattingContext): boolean {
return !Rules.IsFunctionDeclContext(context) && !Rules.IsBeforeBlockContext(context)
}

static IsEndOfDecoratorContextOnSameLine(context: FormattingContext): boolean {
return context.TokensAreOnSameLine() &&
context.contextNode.decorators &&
Expand Down
8 changes: 8 additions & 0 deletions tests/cases/fourslash/formatOnEnterFunctionDeclaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// <reference path="fourslash.ts"/>

/////*0*/function listAPIFiles(path: string): string[] {/*1*/ }

goTo.marker("1");
edit.insertLine("");
goTo.marker("0");
verify.currentLineContentIs("function listAPIFiles(path: string): string[] {");