clang-format: Add an additional value to AlignAfterOpenBracket: AlwaysBreak.

Summary:
If this option is set, clang-format will always insert a line wrap, e.g.
before the first parameter of a function call unless all parameters fit
on the same line. This obviates the need to make a decision on the
alignment itself.

Use this style for Google's JavaScript style and add some minor tweaks
to correctly handle nested blocks etc. with it. Don't use this option
for for/while loops.

Reviewers: klimek

Subscribers: klimek, cfe-commits

Differential Revision: http://reviews.llvm.org/D14104

llvm-svn: 251405
This commit is contained in:
Daniel Jasper 2015-10-27 12:38:37 +00:00
parent 244d27149a
commit 6501f7e8fd
8 changed files with 179 additions and 87 deletions

View File

@ -150,16 +150,37 @@ the configuration (without a prefix: ``Auto``).
**AccessModifierOffset** (``int``)
The extra indent or outdent of access modifiers, e.g. ``public:``.
**AlignAfterOpenBracket** (``bool``)
**AlignAfterOpenBracket** (``BracketAlignmentStyle``)
If ``true``, horizontally aligns arguments after an open bracket.
This applies to round brackets (parentheses), angle brackets and square
brackets. This will result in formattings like
.. code-block:: c++
Possible values:
* ``BAS_Align`` (in configuration: ``Align``)
Align parameters on the open bracket, e.g.:
.. code-block:: c++
someLongFunction(argument1,
argument2);
* ``BAS_DontAlign`` (in configuration: ``DontAlign``)
Don't align, instead use ``ContinuationIndentWidth``, e.g.:
.. code-block:: c++
someLongFunction(argument1,
argument2);
* ``BAS_AlwaysBreak`` (in configuration: ``AlwaysBreak``)
Always break after an open bracket, if the parameters don't fit
on a single line, e.g.:
.. code-block:: c++
someLongFunction(
argument1, argument2);
someLongFunction(argument1,
argument2);
**AlignConsecutiveAssignments** (``bool``)
If ``true``, aligns consecutive assignments.
@ -287,6 +308,9 @@ the configuration (without a prefix: ``Auto``).
* ``bool IndentBraces`` Indent the wrapped braces themselves.
**BreakAfterJavaFieldAnnotations** (``bool``)
Break after each annotation on a field in Java files.
**BreakBeforeBinaryOperators** (``BinaryOperatorStyle``)
The way to wrap binary operators.

View File

@ -43,15 +43,34 @@ struct FormatStyle {
/// \brief The extra indent or outdent of access modifiers, e.g. \c public:.
int AccessModifierOffset;
/// \brief Different styles for aligning after open brackets.
enum BracketAlignmentStyle {
/// \brief Align parameters on the open bracket, e.g.:
/// \code
/// someLongFunction(argument1,
/// argument2);
/// \endcode
BAS_Align,
/// \brief Don't align, instead use \c ContinuationIndentWidth, e.g.:
/// \code
/// someLongFunction(argument1,
/// argument2);
/// \endcode
BAS_DontAlign,
/// \brief Always break after an open bracket, if the parameters don't fit
/// on a single line, e.g.:
/// \code
/// someLongFunction(
/// argument1, argument2);
/// \endcode
BAS_AlwaysBreak,
};
/// \brief If \c true, horizontally aligns arguments after an open bracket.
///
/// This applies to round brackets (parentheses), angle brackets and square
/// brackets. This will result in formattings like
/// \code
/// someLongFunction(argument1,
/// argument2);
/// \endcode
bool AlignAfterOpenBracket;
/// brackets.
BracketAlignmentStyle AlignAfterOpenBracket;
/// \brief If \c true, aligns consecutive assignments.
///

View File

@ -327,8 +327,17 @@ void ContinuationIndenter::addTokenOnCurrentLine(LineState &State, bool DryRun,
State.Stack.back().ColonPos = State.Column + Spaces + Current.ColumnWidth;
}
if (Style.AlignAfterOpenBracket && Previous.opensScope() &&
Previous.isNot(TT_ObjCMethodExpr) &&
// In "AlwaysBreak" mode, enforce wrapping directly after the parenthesis by
// disallowing any further line breaks if there is no line break after the
// opening parenthesis. Don't break if it doesn't conserve columns.
if (Style.AlignAfterOpenBracket == FormatStyle::BAS_AlwaysBreak &&
Previous.is(tok::l_paren) && State.Column > getNewLineColumn(State) &&
(!Previous.Previous ||
!Previous.Previous->isOneOf(tok::kw_for, tok::kw_while, tok::kw_switch)))
State.Stack.back().NoLineBreak = true;
if (Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign &&
Previous.opensScope() && Previous.isNot(TT_ObjCMethodExpr) &&
(Current.isNot(TT_LineComment) || Previous.BlockKind == BK_BracedInit))
State.Stack.back().Indent = State.Column + Spaces;
if (State.Stack.back().AvoidBinPacking && startsNextParameter(Current, Style))
@ -794,8 +803,8 @@ void ContinuationIndenter::moveStatePastFakeLParens(LineState &State,
(Style.AlignOperands || *I < prec::Assignment) &&
(!Previous || Previous->isNot(tok::kw_return) ||
(Style.Language != FormatStyle::LK_Java && *I > 0)) &&
(Style.AlignAfterOpenBracket || *I != prec::Comma ||
Current.NestingLevel == 0))
(Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign ||
*I != prec::Comma || Current.NestingLevel == 0))
NewParenState.Indent =
std::max(std::max(State.Column, NewParenState.Indent),
State.Stack.back().LastSpace);
@ -874,8 +883,15 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
bool BreakBeforeParameter = false;
unsigned NestedBlockIndent = std::max(State.Stack.back().StartOfFunctionCall,
State.Stack.back().NestedBlockIndent);
// Generally inherit NoLineBreak from the current scope to nested scope.
// However, don't do this for nested blocks, e.g. lambdas as these follow
// different indentation rules.
bool NoLineBreak = State.Stack.back().NoLineBreak ||
(Current.is(TT_TemplateOpener) &&
State.Stack.back().ContainsUnwrappedBuilder);
if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
if (Current.opensBlockTypeList(Style)) {
NoLineBreak = false;
NewIndent = State.Stack.back().NestedBlockIndent + Style.IndentWidth;
NewIndent = std::min(State.Column + 2, NewIndent);
++NewIndentLevel;
@ -933,9 +949,6 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State,
}
}
}
bool NoLineBreak = State.Stack.back().NoLineBreak ||
(Current.is(TT_TemplateOpener) &&
State.Stack.back().ContainsUnwrappedBuilder);
State.Stack.push_back(ParenState(NewIndent, NewIndentLevel, LastSpace,
AvoidBinPacking, NoLineBreak));
State.Stack.back().NestedBlockIndent = NestedBlockIndent;
@ -974,7 +987,7 @@ void ContinuationIndenter::moveStateToNewBlock(LineState &State) {
State.Stack.push_back(ParenState(
NewIndent, /*NewIndentLevel=*/State.Stack.back().IndentLevel + 1,
State.Stack.back().LastSpace, /*AvoidBinPacking=*/true,
State.Stack.back().NoLineBreak));
/*NoLineBreak=*/false));
State.Stack.back().NestedBlockIndent = NestedBlockIndent;
State.Stack.back().BreakBeforeParameter = true;
}

View File

@ -128,6 +128,18 @@ struct ScalarEnumerationTraits<FormatStyle::NamespaceIndentationKind> {
}
};
template <> struct ScalarEnumerationTraits<FormatStyle::BracketAlignmentStyle> {
static void enumeration(IO &IO, FormatStyle::BracketAlignmentStyle &Value) {
IO.enumCase(Value, "Align", FormatStyle::BAS_Align);
IO.enumCase(Value, "DontAlign", FormatStyle::BAS_DontAlign);
IO.enumCase(Value, "AlwaysBreak", FormatStyle::BAS_AlwaysBreak);
// For backward compatibility.
IO.enumCase(Value, "true", FormatStyle::BAS_Align);
IO.enumCase(Value, "false", FormatStyle::BAS_DontAlign);
}
};
template <> struct ScalarEnumerationTraits<FormatStyle::PointerAlignmentStyle> {
static void enumeration(IO &IO, FormatStyle::PointerAlignmentStyle &Value) {
IO.enumCase(Value, "Middle", FormatStyle::PAS_Middle);
@ -425,7 +437,7 @@ FormatStyle getLLVMStyle() {
LLVMStyle.Language = FormatStyle::LK_Cpp;
LLVMStyle.AccessModifierOffset = -2;
LLVMStyle.AlignEscapedNewlinesLeft = false;
LLVMStyle.AlignAfterOpenBracket = true;
LLVMStyle.AlignAfterOpenBracket = FormatStyle::BAS_Align;
LLVMStyle.AlignOperands = true;
LLVMStyle.AlignTrailingComments = true;
LLVMStyle.AlignConsecutiveAssignments = false;
@ -523,7 +535,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
GoogleStyle.PenaltyBreakBeforeFirstCallParameter = 1;
if (Language == FormatStyle::LK_Java) {
GoogleStyle.AlignAfterOpenBracket = false;
GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
GoogleStyle.AlignOperands = false;
GoogleStyle.AlignTrailingComments = false;
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
@ -534,11 +546,12 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
GoogleStyle.SpaceAfterCStyleCast = true;
GoogleStyle.SpacesBeforeTrailingComments = 1;
} else if (Language == FormatStyle::LK_JavaScript) {
GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
GoogleStyle.BreakBeforeTernaryOperators = false;
GoogleStyle.MaxEmptyLinesToKeep = 3;
GoogleStyle.SpacesInContainerLiterals = false;
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
} else if (Language == FormatStyle::LK_Proto) {
GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_None;
GoogleStyle.SpacesInContainerLiterals = false;
@ -588,7 +601,7 @@ FormatStyle getMozillaStyle() {
FormatStyle getWebKitStyle() {
FormatStyle Style = getLLVMStyle();
Style.AccessModifierOffset = -4;
Style.AlignAfterOpenBracket = false;
Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
Style.AlignOperands = false;
Style.AlignTrailingComments = false;
Style.BreakBeforeBinaryOperators = FormatStyle::BOS_All;

View File

@ -155,7 +155,7 @@ void CommaSeparatedList::precomputeFormattingInfos(const FormatToken *Token) {
return;
// Column format doesn't really make sense if we don't align after brackets.
if (!Style.AlignAfterOpenBracket)
if (Style.AlignAfterOpenBracket == FormatStyle::BAS_DontAlign)
return;
FormatToken *ItemBegin = Token->Next;

View File

@ -390,12 +390,8 @@ private:
}
void updateParameterCount(FormatToken *Left, FormatToken *Current) {
if (Current->is(TT_LambdaLSquare) ||
(Current->is(tok::caret) && Current->is(TT_UnaryOperator)) ||
(Style.Language == FormatStyle::LK_JavaScript &&
Current->is(Keywords.kw_function))) {
if (Current->is(tok::l_brace) && !Current->is(TT_DictLiteral))
++Left->BlockParameterCount;
}
if (Current->is(tok::comma)) {
++Left->ParameterCount;
if (!Left->Role)
@ -1760,7 +1756,8 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Left.is(tok::colon) && Left.is(TT_ObjCMethodExpr))
return Line.MightBeFunctionDecl ? 50 : 500;
if (Left.is(tok::l_paren) && InFunctionDecl && Style.AlignAfterOpenBracket)
if (Left.is(tok::l_paren) && InFunctionDecl &&
Style.AlignAfterOpenBracket != FormatStyle::BAS_DontAlign)
return 100;
if (Left.is(tok::l_paren) && Left.Previous &&
Left.Previous->isOneOf(tok::kw_if, tok::kw_for))
@ -1772,7 +1769,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
if (Left.is(TT_TemplateOpener))
return 100;
if (Left.opensScope()) {
if (!Style.AlignAfterOpenBracket)
if (Style.AlignAfterOpenBracket == FormatStyle::BAS_DontAlign)
return 0;
return Left.ParameterCount > 1 ? Style.PenaltyBreakBeforeFirstCallParameter
: 19;

View File

@ -3503,7 +3503,7 @@ TEST_F(FormatTest, NoOperandAlignment) {
" * cccccccccccccccccccccccccccccccccccc;",
Style);
Style.AlignAfterOpenBracket = false;
Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
verifyFormat("return (a > b\n"
" // comment1\n"
" // comment2\n"
@ -4307,7 +4307,7 @@ TEST_F(FormatTest, AlignsAfterOpenBracket) {
"SomeLongVariableName->someFunction(foooooooo(aaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaaaaaaa));");
FormatStyle Style = getLLVMStyle();
Style.AlignAfterOpenBracket = false;
Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
verifyFormat("void aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa(\n"
" aaaaaaaaaaa aaaaaaaa, aaaaaaaaa aaaaaaa) {}",
Style);
@ -4336,17 +4336,17 @@ TEST_F(FormatTest, ParenthesesAndOperandAlignment) {
verifyFormat("int a = f(aaaaaaaaaaaaaaaaaaaaaa &&\n"
" bbbbbbbbbbbbbbbbbbbbbb);",
Style);
Style.AlignAfterOpenBracket = true;
Style.AlignAfterOpenBracket = FormatStyle::BAS_Align;
Style.AlignOperands = false;
verifyFormat("int a = f(aaaaaaaaaaaaaaaaaaaaaa &&\n"
" bbbbbbbbbbbbbbbbbbbbbb);",
Style);
Style.AlignAfterOpenBracket = false;
Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
Style.AlignOperands = true;
verifyFormat("int a = f(aaaaaaaaaaaaaaaaaaaaaa &&\n"
" bbbbbbbbbbbbbbbbbbbbbb);",
Style);
Style.AlignAfterOpenBracket = false;
Style.AlignAfterOpenBracket = FormatStyle::BAS_DontAlign;
Style.AlignOperands = false;
verifyFormat("int a = f(aaaaaaaaaaaaaaaaaaaaaa &&\n"
" bbbbbbbbbbbbbbbbbbbbbb);",
@ -9533,7 +9533,6 @@ TEST_F(FormatTest, GetsCorrectBasedOnStyle) {
TEST_F(FormatTest, ParsesConfigurationBools) {
FormatStyle Style = {};
Style.Language = FormatStyle::LK_Cpp;
CHECK_PARSE_BOOL(AlignAfterOpenBracket);
CHECK_PARSE_BOOL(AlignEscapedNewlinesLeft);
CHECK_PARSE_BOOL(AlignOperands);
CHECK_PARSE_BOOL(AlignTrailingComments);
@ -9545,8 +9544,8 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
CHECK_PARSE_BOOL(AllowShortIfStatementsOnASingleLine);
CHECK_PARSE_BOOL(AllowShortLoopsOnASingleLine);
CHECK_PARSE_BOOL(AlwaysBreakTemplateDeclarations);
CHECK_PARSE_BOOL(BinPackParameters);
CHECK_PARSE_BOOL(BinPackArguments);
CHECK_PARSE_BOOL(BinPackParameters);
CHECK_PARSE_BOOL(BreakBeforeTernaryOperators);
CHECK_PARSE_BOOL(BreakConstructorInitializersBeforeComma);
CHECK_PARSE_BOOL(ConstructorInitializerAllOnOneLineOrOnePerLine);
@ -9636,6 +9635,19 @@ TEST_F(FormatTest, ParsesConfiguration) {
CHECK_PARSE("BreakBeforeBinaryOperators: true", BreakBeforeBinaryOperators,
FormatStyle::BOS_All);
Style.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
CHECK_PARSE("AlignAfterOpenBracket: Align", AlignAfterOpenBracket,
FormatStyle::BAS_Align);
CHECK_PARSE("AlignAfterOpenBracket: DontAlign", AlignAfterOpenBracket,
FormatStyle::BAS_DontAlign);
CHECK_PARSE("AlignAfterOpenBracket: AlwaysBreak", AlignAfterOpenBracket,
FormatStyle::BAS_AlwaysBreak);
// For backward compatibility:
CHECK_PARSE("AlignAfterOpenBracket: false", AlignAfterOpenBracket,
FormatStyle::BAS_DontAlign);
CHECK_PARSE("AlignAfterOpenBracket: true", AlignAfterOpenBracket,
FormatStyle::BAS_Align);
Style.UseTab = FormatStyle::UT_ForIndentation;
CHECK_PARSE("UseTab: Never", UseTab, FormatStyle::UT_Never);
CHECK_PARSE("UseTab: ForIndentation", UseTab, FormatStyle::UT_ForIndentation);

View File

@ -49,7 +49,8 @@ protected:
static void verifyFormat(
llvm::StringRef Code,
const FormatStyle &Style = getGoogleStyle(FormatStyle::LK_JavaScript)) {
EXPECT_EQ(Code.str(), format(test::messUp(Code), Style));
std::string result = format(test::messUp(Code), Style);
EXPECT_EQ(Code.str(), result) << "Formatted:\n" << result;
}
};
@ -278,27 +279,28 @@ TEST_F(FormatTestJS, ArrayLiterals) {
" bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" ccccccccccccccccccccccccccc\n"
"];");
verifyFormat("var someVariable = SomeFuntion([\n"
verifyFormat("var someVariable = SomeFunction([\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" ccccccccccccccccccccccccccc\n"
"]);");
verifyFormat("var someVariable = SomeFuntion([\n"
verifyFormat("var someVariable = SomeFunction([\n"
" [aaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbb],\n"
"]);",
getGoogleJSStyleWithColumns(51));
verifyFormat("var someVariable = SomeFuntion(aaaa, [\n"
verifyFormat("var someVariable = SomeFunction(aaaa, [\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" ccccccccccccccccccccccccccc\n"
"]);");
verifyFormat("var someVariable = SomeFuntion(aaaa,\n"
" [\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" ccccccccccccccccccccccccccc\n"
" ],\n"
" aaaa);");
verifyFormat("var someVariable = SomeFunction(\n"
" aaaa,\n"
" [\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"
" ccccccccccccccccccccccccccc\n"
" ],\n"
" aaaa);");
verifyFormat("someFunction([], {a: a});");
}
@ -320,14 +322,11 @@ TEST_F(FormatTestJS, FunctionLiterals) {
" style: {direction: ''}\n"
" }\n"
"};");
EXPECT_EQ("abc = xyz ?\n"
" function() {\n"
" return 1;\n"
" } :\n"
" function() {\n"
" return -1;\n"
" };",
format("abc=xyz?function(){return 1;}:function(){return -1;};"));
verifyFormat("abc = xyz ? function() {\n"
" return 1;\n"
"} : function() {\n"
" return -1;\n"
"};");
verifyFormat("var closure = goog.bind(\n"
" function() { // comment\n"
@ -379,17 +378,13 @@ TEST_F(FormatTestJS, FunctionLiterals) {
" someFunction();\n"
" }, this), aaaaaaaaaaaaaaaaa);");
// FIXME: This is not ideal yet.
verifyFormat("someFunction(goog.bind(\n"
" function() {\n"
" doSomething();\n"
" doSomething();\n"
" },\n"
" this),\n"
" goog.bind(function() {\n"
" doSomething();\n"
" doSomething();\n"
" }, this));");
verifyFormat("someFunction(goog.bind(function() {\n"
" doSomething();\n"
" doSomething();\n"
"}, this), goog.bind(function() {\n"
" doSomething();\n"
" doSomething();\n"
"}, this));");
// FIXME: This is bad, we should be wrapping before "function() {".
verifyFormat("someFunction(function() {\n"
@ -472,16 +467,16 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) {
" doFoo();\n"
" doBaz();\n"
" });\n");
// FIXME: Here, we should probably break right after the "(" for consistency.
verifyFormat("promise.then([],\n"
" function success() {\n"
" doFoo();\n"
" doBar();\n"
" },\n"
" function error() {\n"
" doFoo();\n"
" doBaz();\n"
" });\n");
verifyFormat("promise.then(\n"
" [],\n"
" function success() {\n"
" doFoo();\n"
" doBar();\n"
" },\n"
" function error() {\n"
" doFoo();\n"
" doBaz();\n"
" });\n");
verifyFormat("getSomeLongPromise()\n"
" .then(function(value) { body(); })\n"
@ -523,13 +518,13 @@ TEST_F(FormatTestJS, ArrowFunctions) {
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa) =>\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
"};");
verifyFormat(
"var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&\n"
" aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));");
verifyFormat(
"var a = a.aaaaaaa((a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) ?\n"
" aaaaaaaaaaaaaaaaaaaaa(bbbbbbb) :\n"
" aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));");
verifyFormat("var a = a.aaaaaaa(\n"
" (a: a) => aaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) &&\n"
" aaaaaaaaaaaaaaaaaaaaaaaaa(bbbbbbb));");
verifyFormat("var a = a.aaaaaaa(\n"
" (a: a) => aaaaaaaaaaaaaaaaaaaaa(bbbbbbbbb) ?\n"
" aaaaaaaaaaaaaaaaaaaaa(bbbbbbb) :\n"
" aaaaaaaaaaaaaaaaaaaaa(bbbbbbb));");
// FIXME: This is bad, we should be wrapping before "() => {".
verifyFormat("someFunction(() => {\n"
@ -924,8 +919,9 @@ TEST_F(FormatTestJS, TypeArguments) {
verifyFormat("function f(): List<any> {}");
verifyFormat("function aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa():\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb {}");
verifyFormat("function aaaaaaaaaa(aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaa):\n"
verifyFormat("function aaaaaaaaaa(\n"
" aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaa,\n"
" aaaaaaaaaaaaaaaa: aaaaaaaaaaaaaaaaaaa):\n"
" aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa {}");
}
@ -951,5 +947,23 @@ TEST_F(FormatTestJS, IndexSignature) {
verifyFormat("var x: {[k: string]: v};");
}
TEST_F(FormatTestJS, WrapAfterParen) {
verifyFormat("xxxxxxxxxxx(\n"
" aaa, aaa);",
getGoogleJSStyleWithColumns(20));
verifyFormat("xxxxxxxxxxx(\n"
" aaa, aaa, aaa,\n"
" aaa, aaa, aaa);",
getGoogleJSStyleWithColumns(20));
verifyFormat("xxxxxxxxxxx(\n"
" aaaaaaaaaaaaaaaaaaaaaaaa,\n"
" function(x) {\n"
" y(); //\n"
" });",
getGoogleJSStyleWithColumns(40));
verifyFormat("while (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa &&\n"
" bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb) {\n}");
}
} // end namespace tooling
} // end namespace clang