From 5dde2b964f7225ba158ecd2eb18d53fae1e01a39 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 8 Jan 2016 17:56:37 +0900 Subject: [PATCH 1/2] do not add space between comma and close bracket --- src/services/formatting/rules.ts | 6 +++++- tests/cases/fourslash/formattingOptionsChange.ts | 6 +++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/services/formatting/rules.ts b/src/services/formatting/rules.ts index 23d5c0db8c..2df78df01d 100644 --- a/src/services/formatting/rules.ts +++ b/src/services/formatting/rules.ts @@ -444,7 +444,7 @@ namespace ts.formatting { /// // Insert space after comma delimiter - this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Space)); + this.SpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext, Rules.IsNextTokenNotCloseBracket), RuleAction.Space)); this.NoSpaceAfterComma = new Rule(RuleDescriptor.create3(SyntaxKind.CommaToken, Shared.TokenRange.Any), RuleOperation.create2(new RuleOperationContext(Rules.IsSameLineTokenContext), RuleAction.Delete)); // Insert space before and after binary operators @@ -711,6 +711,10 @@ namespace ts.formatting { return context.currentTokenSpan.kind !== SyntaxKind.CommaToken; } + static IsNextTokenNotCloseBracket(context: FormattingContext): boolean { + return context.nextTokenSpan.kind !== SyntaxKind.CloseBracketToken; + } + static IsArrowFunctionContext(context: FormattingContext): boolean { return context.contextNode.kind === SyntaxKind.ArrowFunction; } diff --git a/tests/cases/fourslash/formattingOptionsChange.ts b/tests/cases/fourslash/formattingOptionsChange.ts index a9c49d7250..bf28d101af 100644 --- a/tests/cases/fourslash/formattingOptionsChange.ts +++ b/tests/cases/fourslash/formattingOptionsChange.ts @@ -1,6 +1,6 @@ /// -/////*InsertSpaceAfterCommaDelimiter*/[1,2, 3]; +/////*InsertSpaceAfterCommaDelimiter*/[1,2, 3];[72,]; /////*InsertSpaceAfterSemicolonInForStatements*/for (i = 0;i; i++); /////*InsertSpaceBeforeAndAfterBinaryOperators*/1+2- 3 /////*InsertSpaceAfterKeywordsInControlFlowStatements*/if (true) { } @@ -13,13 +13,13 @@ /////*PlaceOpenBraceOnNewLineForControlBlocks*/if (true) { ////} -runTest("InsertSpaceAfterCommaDelimiter", "[1, 2, 3];", "[1,2,3];"); +runTest("InsertSpaceAfterCommaDelimiter", "[1, 2, 3];[72,];", "[1,2,3];[72,];"); runTest("InsertSpaceAfterSemicolonInForStatements", "for (i = 0; i; i++);", "for (i = 0;i;i++);"); runTest("InsertSpaceBeforeAndAfterBinaryOperators", "1 + 2 - 3", "1+2-3"); runTest("InsertSpaceAfterKeywordsInControlFlowStatements", "if (true) { }", "if(true) { }"); runTest("InsertSpaceAfterFunctionKeywordForAnonymousFunctions", "(function () { })", "(function() { })"); runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis", " ( 1 )", " (1)"); -runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets", "[ 1 ];[];[];[ , ];", "[1];[];[];[, ];"); +runTest("InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets", "[ 1 ];[];[];[ , ];", "[1];[];[];[,];"); runTest("InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces", "`${ 1 }`; `${ 1 }`", "`${1}`; `${1}`"); runTest("PlaceOpenBraceOnNewLineForFunctions", "class foo", "class foo {"); runTest("PlaceOpenBraceOnNewLineForControlBlocks", "if ( true )", "if ( true ) {"); From 5431e09f928aaf839ff4377c031c9d18fa397c49 Mon Sep 17 00:00:00 2001 From: Kagami Sascha Rosylight Date: Fri, 8 Jan 2016 18:01:02 +0900 Subject: [PATCH 2/2] add more spaces on test --- tests/cases/fourslash/formattingOptionsChange.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cases/fourslash/formattingOptionsChange.ts b/tests/cases/fourslash/formattingOptionsChange.ts index bf28d101af..f266a8e96c 100644 --- a/tests/cases/fourslash/formattingOptionsChange.ts +++ b/tests/cases/fourslash/formattingOptionsChange.ts @@ -1,6 +1,6 @@ /// -/////*InsertSpaceAfterCommaDelimiter*/[1,2, 3];[72,]; +/////*InsertSpaceAfterCommaDelimiter*/[1,2, 3];[ 72 , ]; /////*InsertSpaceAfterSemicolonInForStatements*/for (i = 0;i; i++); /////*InsertSpaceBeforeAndAfterBinaryOperators*/1+2- 3 /////*InsertSpaceAfterKeywordsInControlFlowStatements*/if (true) { }