clang-format: Don't format unrelated nested blocks.
With this change: SomeFunction( [] { int i; return i; // Format this line. }, [] { return 2; // Don't "fix" this. }); llvm-svn: 262216
This commit is contained in:
parent
6bb15021b3
commit
35ca66debf
|
@ -863,7 +863,9 @@ UnwrappedLineFormatter::format(const SmallVectorImpl<AnnotatedLine *> &Lines,
|
||||||
// If no token in the current line is affected, we still need to format
|
// If no token in the current line is affected, we still need to format
|
||||||
// affected children.
|
// affected children.
|
||||||
if (TheLine.ChildrenAffected)
|
if (TheLine.ChildrenAffected)
|
||||||
format(TheLine.Children, DryRun);
|
for (const FormatToken *Tok = TheLine.First; Tok; Tok = Tok->Next)
|
||||||
|
if (!Tok->Children.empty())
|
||||||
|
format(Tok->Children, DryRun);
|
||||||
|
|
||||||
// Adapt following lines on the current indent level to the same level
|
// Adapt following lines on the current indent level to the same level
|
||||||
// unless the current \c AnnotatedLine is not at the beginning of a line.
|
// unless the current \c AnnotatedLine is not at the beginning of a line.
|
||||||
|
|
|
@ -278,6 +278,23 @@ TEST_F(FormatTestSelective, IndividualStatementsOfNestedBlocks) {
|
||||||
" };\n"
|
" };\n"
|
||||||
"});",
|
"});",
|
||||||
0, 0));
|
0, 0));
|
||||||
|
EXPECT_EQ("SomeFunction(\n"
|
||||||
|
" [] {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" return i;\n" // Format this line.
|
||||||
|
" },\n"
|
||||||
|
" [] {\n"
|
||||||
|
" return 2;\n" // Don't fix this.
|
||||||
|
" });",
|
||||||
|
format("SomeFunction(\n"
|
||||||
|
" [] {\n"
|
||||||
|
" int i;\n"
|
||||||
|
" return i;\n" // Format this line.
|
||||||
|
" },\n"
|
||||||
|
" [] {\n"
|
||||||
|
" return 2;\n" // Don't fix this.
|
||||||
|
" });",
|
||||||
|
40, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(FormatTestSelective, WrongIndent) {
|
TEST_F(FormatTestSelective, WrongIndent) {
|
||||||
|
|
Loading…
Reference in New Issue