From b729cf5cb34e7835a3ff606b0fdf3a10d2d400db Mon Sep 17 00:00:00 2001 From: Oleksandr T Date: Fri, 20 Mar 2020 23:20:26 +0200 Subject: [PATCH] fix(37431): allow only one space between async keyword and method name --- src/services/formatting/rules.ts | 2 +- tests/cases/fourslash/formatAsyncClassMethod1.ts | 12 ++++++++++++ tests/cases/fourslash/formatAsyncClassMethod2.ts | 12 ++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 tests/cases/fourslash/formatAsyncClassMethod1.ts create mode 100644 tests/cases/fourslash/formatAsyncClassMethod2.ts diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index d5db98a1d30d0..4d6eb8f7a99e6 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -129,7 +129,7 @@ namespace ts.formatting { // Async-await rule("SpaceBetweenAsyncAndOpenParen", SyntaxKind.AsyncKeyword, SyntaxKind.OpenParenToken, [isArrowFunctionContext, isNonJsxSameLineTokenContext], RuleAction.InsertSpace), - rule("SpaceBetweenAsyncAndFunctionKeyword", SyntaxKind.AsyncKeyword, SyntaxKind.FunctionKeyword, [isNonJsxSameLineTokenContext], RuleAction.InsertSpace), + rule("SpaceBetweenAsyncAndFunctionKeyword", SyntaxKind.AsyncKeyword, [SyntaxKind.FunctionKeyword, SyntaxKind.Identifier], [isNonJsxSameLineTokenContext], RuleAction.InsertSpace), // Template string rule("NoSpaceBetweenTagAndTemplateString", [SyntaxKind.Identifier, SyntaxKind.CloseParenToken], [SyntaxKind.NoSubstitutionTemplateLiteral, SyntaxKind.TemplateHead], [isNonJsxSameLineTokenContext], RuleAction.DeleteSpace), diff --git a/tests/cases/fourslash/formatAsyncClassMethod1.ts b/tests/cases/fourslash/formatAsyncClassMethod1.ts new file mode 100644 index 0000000000000..b120a8c771ee1 --- /dev/null +++ b/tests/cases/fourslash/formatAsyncClassMethod1.ts @@ -0,0 +1,12 @@ +/// + +////class Foo { +//// async foo() {} +////} + +format.document(); +verify.currentFileContentIs( +`class Foo { + async foo() { } +}` +); diff --git a/tests/cases/fourslash/formatAsyncClassMethod2.ts b/tests/cases/fourslash/formatAsyncClassMethod2.ts new file mode 100644 index 0000000000000..6901778b0a625 --- /dev/null +++ b/tests/cases/fourslash/formatAsyncClassMethod2.ts @@ -0,0 +1,12 @@ +/// + +////class Foo { +//// private async foo() {} +////} + +format.document(); +verify.currentFileContentIs( +`class Foo { + private async foo() { } +}` +);