Skip to content

Commit a74ca18

Browse files
committed
adding rules, ParenthesizedType not yet
1 parent c0a87e9 commit a74ca18

3 files changed

Lines changed: 35 additions & 3 deletions

File tree

src/services/formatting/rules.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,16 @@ namespace ts.formatting {
213213
public NoSpaceBetweenYieldKeywordAndStar: Rule;
214214
public SpaceBetweenYieldOrYieldStarAndOperand: Rule;
215215

216+
// Await-async
217+
public SpaceAfterAwaitKeyword: Rule;
218+
public NoSpaceAfterAwaitKeyword: Rule;
219+
public SpaceBetweenAsyncAndFunctionKeyword: Rule;
220+
public NoSpaceBetweenAsyncAndFunctionKeyword: Rule;
221+
222+
// Tagged template string
223+
public SpaceBetweenTagAndTemplateString: Rule;
224+
public NoSpaceBetweenTagAndTemplateString: Rule;
225+
216226
constructor() {
217227
///
218228
/// Common Rules
@@ -360,6 +370,17 @@ namespace ts.formatting {
360370
this.NoSpaceBetweenYieldKeywordAndStar = new Rule(RuleDescriptor.create1(SyntaxKind.YieldKeyword, SyntaxKind.AsteriskToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), RuleAction.Delete));
361371
this.SpaceBetweenYieldOrYieldStarAndOperand = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.YieldKeyword, SyntaxKind.AsteriskToken]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsYieldOrYieldStarWithOperand), RuleAction.Space));
362372

373+
// Await-async
374+
this.SpaceAfterAwaitKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.AwaitKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
375+
this.NoSpaceAfterAwaitKeyword = new Rule(RuleDescriptor.create3(SyntaxKind.AwaitKeyword, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
376+
this.SpaceBetweenAsyncAndFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
377+
this.NoSpaceBetweenAsyncAndFunctionKeyword = new Rule(RuleDescriptor.create1(SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
378+
379+
// template string
380+
this.SpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
381+
this.NoSpaceBetweenTagAndTemplateString = new Rule(RuleDescriptor.create3(SyntaxKind.Identifier, Shared.TokenRange.FromTokens([SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
382+
383+
363384
// These rules are higher in priority than user-configurable rules.
364385
this.HighPriorityCommonRules =
365386
[
@@ -386,6 +407,12 @@ namespace ts.formatting {
386407
this.NoSpaceBeforeOpenParenInFuncCall,
387408
this.SpaceBeforeBinaryKeywordOperator, this.SpaceAfterBinaryKeywordOperator,
388409
this.SpaceAfterVoidOperator,
410+
this.SpaceAfterAwaitKeyword,
411+
this.NoSpaceAfterAwaitKeyword,
412+
this.SpaceBetweenAsyncAndFunctionKeyword,
413+
this.NoSpaceBetweenAsyncAndFunctionKeyword,
414+
this.SpaceBetweenTagAndTemplateString,
415+
this.NoSpaceBetweenTagAndTemplateString,
389416

390417
// TypeScript-specific rules
391418
this.NoSpaceAfterConstructor, this.NoSpaceAfterModuleImport,

src/services/formatting/smartIndenter.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,14 @@ namespace ts.formatting {
429429
case SyntaxKind.ArrayBindingPattern:
430430
case SyntaxKind.ObjectBindingPattern:
431431
case SyntaxKind.JsxElement:
432+
case SyntaxKind.MethodSignature:
433+
case SyntaxKind.CallSignature:
434+
case SyntaxKind.ConstructSignature:
432435
case SyntaxKind.FunctionType:
436+
case SyntaxKind.UnionType:
437+
case SyntaxKind.Parameter:
438+
case SyntaxKind.TaggedTemplateExpression:
439+
case SyntaxKind.AwaitExpression:
433440
return true;
434441
}
435442
return false;
@@ -449,8 +456,6 @@ namespace ts.formatting {
449456
case SyntaxKind.FunctionDeclaration:
450457
case SyntaxKind.FunctionExpression:
451458
case SyntaxKind.MethodDeclaration:
452-
case SyntaxKind.MethodSignature:
453-
case SyntaxKind.CallSignature:
454459
case SyntaxKind.ArrowFunction:
455460
case SyntaxKind.Constructor:
456461
case SyntaxKind.GetAccessor:

tests/cases/fourslash/smartIndentOnUnclosedFunctionDeclaration04.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ function verifyIndentationAfterNewLine(marker: string, indentation: number): voi
1212
verifyIndentationAfterNewLine("1", 4);
1313
verifyIndentationAfterNewLine("2", 4);
1414
verifyIndentationAfterNewLine("3", 4);
15-
verifyIndentationAfterNewLine("4", 4);
15+
verifyIndentationAfterNewLine("4", 8);
1616
verifyIndentationAfterNewLine("5", 4);
1717
verifyIndentationAfterNewLine("6", 4);

0 commit comments

Comments
 (0)