[PATCH] D101033: [clang-format] fix indent in alignChainedConditionals
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Apr 26 02:07:21 PDT 2021
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5987d7c59da5: [clang-format] fix indent in alignChainedConditionals (authored by krasimir).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D101033/new/
https://reviews.llvm.org/D101033
Files:
clang/lib/Format/WhitespaceManager.cpp
clang/unittests/Format/FormatTest.cpp
Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -6459,6 +6459,30 @@
" bbbb ? cccccccccccccccccc :\n"
" ddddd;\n",
Style);
+
+ EXPECT_EQ(
+ "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n"
+ " /*\n"
+ " */\n"
+ " function() {\n"
+ " try {\n"
+ " return JJJJJJJJJJJJJJ(\n"
+ " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n"
+ " }\n"
+ " } :\n"
+ " function() {};",
+ format(
+ "MMMMMMMMMMMMMMMMMMMMMMMMMMM = A ?\n"
+ " /*\n"
+ " */\n"
+ " function() {\n"
+ " try {\n"
+ " return JJJJJJJJJJJJJJ(\n"
+ " pppppppppppppppppppppppppppppppppppppppppppppppppp);\n"
+ " }\n"
+ " } :\n"
+ " function() {};",
+ getGoogleStyle(FormatStyle::LK_JavaScript)));
}
TEST_F(FormatTest, BreaksConditionalExpressionsAfterOperator) {
Index: clang/lib/Format/WhitespaceManager.cpp
===================================================================
--- clang/lib/Format/WhitespaceManager.cpp
+++ clang/lib/Format/WhitespaceManager.cpp
@@ -778,12 +778,11 @@
Changes, /*StartAt=*/0);
} else {
static auto AlignWrappedOperand = [](Change const &C) {
- auto Previous = C.Tok->getPreviousNonComment(); // Previous;
+ FormatToken *Previous = C.Tok->getPreviousNonComment();
return C.NewlinesBefore && Previous && Previous->is(TT_ConditionalExpr) &&
- (Previous->is(tok::question) ||
- (Previous->is(tok::colon) &&
- (C.Tok->FakeLParens.size() == 0 ||
- C.Tok->FakeLParens.back() != prec::Conditional)));
+ (Previous->is(tok::colon) &&
+ (C.Tok->FakeLParens.size() == 0 ||
+ C.Tok->FakeLParens.back() != prec::Conditional));
};
// Ensure we keep alignment of wrapped operands with non-wrapped operands
// Since we actually align the operators, the wrapped operands need the
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D101033.340454.patch
Type: text/x-patch
Size: 2276 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210426/898d58f4/attachment.bin>
More information about the cfe-commits
mailing list