Skip to content

Commit 84ff2f8

Browse files
Merge pull request #3617 from DickvdBrink/format-protected
Format after protected modifer
2 parents 3d8650c + 822199f commit 84ff2f8

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/services/formatting/rules.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ namespace ts.formatting {
318318
this.NoSpaceAfterModuleImport = new Rule(RuleDescriptor.create2(Shared.TokenRange.FromTokens([SyntaxKind.ModuleKeyword, SyntaxKind.RequireKeyword]), SyntaxKind.OpenParenToken), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete));
319319

320320
// Add a space around certain TypeScript keywords
321-
this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
321+
this.SpaceAfterCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.FromTokens([SyntaxKind.ClassKeyword, SyntaxKind.DeclareKeyword, SyntaxKind.EnumKeyword, SyntaxKind.ExportKeyword, SyntaxKind.ExtendsKeyword, SyntaxKind.GetKeyword, SyntaxKind.ImplementsKeyword, SyntaxKind.ImportKeyword, SyntaxKind.InterfaceKeyword, SyntaxKind.ModuleKeyword, SyntaxKind.NamespaceKeyword, SyntaxKind.PrivateKeyword, SyntaxKind.PublicKeyword, SyntaxKind.ProtectedKeyword, SyntaxKind.SetKeyword, SyntaxKind.StaticKeyword]), Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
322322
this.SpaceBeforeCertainTypeScriptKeywords = new Rule(RuleDescriptor.create4(Shared.TokenRange.Any, Shared.TokenRange.FromTokens([SyntaxKind.ExtendsKeyword, SyntaxKind.ImplementsKeyword])), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space));
323323

324324
// Treat string literals in module names as identifiers, and add a space between the literal and the opening Brace braces, e.g.: module "m2" {

tests/cases/fourslash/formattingOnClasses.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,9 @@
7777
/////*60*/ private foo ( ns : any ) {
7878
/////*61*/ return ns.toString ( ) ;
7979
/////*62*/ }
80-
/////*63*/}
80+
/////*63*/ protected bar ( ) { }
81+
/////*64*/ protected static bar2 ( ) { }
82+
/////*65*/}
8183
format.document();
8284
goTo.marker("1");
8385
verify.currentLineContentIs("class a {");
@@ -204,4 +206,8 @@ verify.currentLineContentIs(" return ns.toString();");
204206
goTo.marker("62");
205207
verify.currentLineContentIs(" }");
206208
goTo.marker("63");
209+
verify.currentLineContentIs(" protected bar() { }");
210+
goTo.marker("64");
211+
verify.currentLineContentIs(" protected static bar2() { }");
212+
goTo.marker("65");
207213
verify.currentLineContentIs("}");

0 commit comments

Comments
 (0)