do not add space between comma and close bracket

This commit is contained in:
Kagami Sascha Rosylight 2016-01-08 17:56:37 +09:00
parent df223bf67d
commit 5dde2b964f
2 changed files with 8 additions and 4 deletions

View file

@ -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;
}

View file

@ -1,6 +1,6 @@
///<reference path="fourslash.ts"/>
/////*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 ) {");