Skip to content

Commit 5e7778b

Browse files
authored
Merge pull request #15491 from SaschaNaz/newformat
No space after new keyword on constructor signature
2 parents 9d53e4c + 61f494e commit 5e7778b

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

src/services/formatting/rules.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace ts.formatting {
8484
public NoSpaceBeforeComma: Rule;
8585

8686
public SpaceAfterCertainKeywords: Rule;
87+
public NoSpaceAfterNewKeywordOnConstructorSignature: Rule;
8788
public SpaceAfterLetConstInVariableDeclaration: Rule;
8889
public NoSpaceBeforeOpenParenInFuncCall: Rule;
8990
public SpaceAfterFunctionInFuncDecl: Rule;
@@ -334,6 +335,7 @@ namespace ts.formatting {
334335
this.NoSpaceBeforeComma = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.CommaToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Delete));
335336

336337
this.SpaceAfterCertainKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.VarKeyword, SyntaxKind.ThrowKeyword, SyntaxKind.NewKeyword, SyntaxKind.DeleteKeyword, SyntaxKind.ReturnKeyword, SyntaxKind.TypeOfKeyword, SyntaxKind.AwaitKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext), RuleAction.Space));
338+
this.NoSpaceAfterNewKeywordOnConstructorSignature = new Rule(RuleDescriptor.create1(SyntaxKind.NewKeyword, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsConstructorSignatureContext), RuleAction.Delete));
337339
this.SpaceAfterLetConstInVariableDeclaration = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.LetKeyword, SyntaxKind.ConstKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsStartOfVariableDeclarationList), RuleAction.Space));
338340
this.NoSpaceBeforeOpenParenInFuncCall = new Rule(RuleDescriptor.create2(Shared.TokenRange.Any, SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsNonJsxSameLineTokenContext, Rules.IsFunctionCallOrNewContext, Rules.IsPreviousTokenNotComma), RuleAction.Delete));
339341
this.SpaceAfterFunctionInFuncDecl = new Rule(RuleDescriptor.create3(SyntaxKind.FunctionKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsFunctionDeclContext), RuleAction.Space));
@@ -530,7 +532,8 @@ namespace ts.formatting {
530532
this.SpaceBeforeAt,
531533
this.NoSpaceAfterAt,
532534
this.SpaceAfterDecorator,
533-
this.NoSpaceBeforeNonNullAssertionOperator
535+
this.NoSpaceBeforeNonNullAssertionOperator,
536+
this.NoSpaceAfterNewKeywordOnConstructorSignature
534537
];
535538

536539
// These rules are applied after high priority rules.
@@ -881,6 +884,10 @@ namespace ts.formatting {
881884
return context.contextNode.kind === SyntaxKind.TypeLiteral; // && context.contextNode.parent.kind !== SyntaxKind.InterfaceDeclaration;
882885
}
883886

887+
static IsConstructorSignatureContext(context: FormattingContext): boolean {
888+
return context.contextNode.kind === SyntaxKind.ConstructSignature;
889+
}
890+
884891
static IsTypeArgumentOrParameterOrAssertion(token: TextRangeWithKind, parent: Node): boolean {
885892
if (token.kind !== SyntaxKind.LessThanToken && token.kind !== SyntaxKind.GreaterThanToken) {
886893
return false;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
/////*1*/interface Gourai { new () {} }
4+
/////*2*/type Stylet = { new () {} }
5+
format.document();
6+
goTo.marker("1");
7+
verify.currentLineContentIs("interface Gourai { new() {} }");
8+
goTo.marker("2");
9+
verify.currentLineContentIs("type Stylet = { new() {} }");

0 commit comments

Comments
 (0)