forked from OSchip/llvm-project
clang-format: Make trailing commas in array inits force one per line.
Before: NSArray *array = @[ @"a", @"a", ]; After: NSArray *array = @[ @"a", @"a", ]; llvm-svn: 230741
This commit is contained in:
parent
7fe82ad80b
commit
308062bd0d
|
@ -1870,9 +1870,12 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
|
|||
// intention is to insert a line break after it in order to make shuffling
|
||||
// around entries easier.
|
||||
const FormatToken *BeforeClosingBrace = nullptr;
|
||||
if (Left.is(tok::l_brace) && Left.BlockKind != BK_Block && Left.MatchingParen)
|
||||
if (Left.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare) &&
|
||||
Left.BlockKind != BK_Block && Left.MatchingParen)
|
||||
BeforeClosingBrace = Left.MatchingParen->Previous;
|
||||
else if (Right.is(tok::r_brace) && Right.BlockKind != BK_Block)
|
||||
else if (Right.MatchingParen &&
|
||||
Right.MatchingParen->isOneOf(tok::l_brace,
|
||||
TT_ArrayInitializerLSquare))
|
||||
BeforeClosingBrace = &Left;
|
||||
if (BeforeClosingBrace && (BeforeClosingBrace->is(tok::comma) ||
|
||||
BeforeClosingBrace->isTrailingComment()))
|
||||
|
|
|
@ -7216,6 +7216,10 @@ TEST_F(FormatTest, ObjCArrayLiterals) {
|
|||
" @\"aaaaaaaaaaaaaaaaa\",\n"
|
||||
" @\"aaaaaaaaaaaaaaaaa\"\n"
|
||||
"];");
|
||||
verifyFormat("NSArray *array = @[\n"
|
||||
" @\"a\",\n"
|
||||
" @\"a\",\n" // Trailing comma -> one per line.
|
||||
"];");
|
||||
|
||||
// We should try to be robust in case someone forgets the "@".
|
||||
verifyFormat("NSArray *some_variable = [\n"
|
||||
|
|
Loading…
Reference in New Issue