Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(160)

Unified Diff: tools/gn/command_format.cc

Issue 770053002: gn format: Special case for single arg function calls containing boolean ops (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@gn-unnecessary-parens
Patch Set: if too Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | tools/gn/command_format_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gn/command_format.cc
diff --git a/tools/gn/command_format.cc b/tools/gn/command_format.cc
index c2870f1433a7cbec81d802bc8b557d378d0bbdf9..9e0914552de04d2d7bbf5b831e5e1de582d006e5 100644
--- a/tools/gn/command_format.cc
+++ b/tools/gn/command_format.cc
@@ -686,10 +686,18 @@ int Printer::FunctionCall(const FunctionCallNode* func_call,
terminator += " {";
terminator += suffix;
+ // Special case to make function calls of one arg taking a long list of
+ // boolean operators not indent.
+ bool continuation_requires_indent =
+ list.size() != 1 || !list[0]->AsBinaryOp() ||
+ (list[0]->AsBinaryOp()->op().value() != "||" &&
+ list[0]->AsBinaryOp()->op().value() != "&&");
+
// 1: Same line.
Printer sub1;
InitializeSub(&sub1);
- sub1.stack_.push_back(IndentState(CurrentColumn(), true, false));
+ sub1.stack_.push_back(
+ IndentState(CurrentColumn(), continuation_requires_indent, false));
int penalty_one_line = 0;
for (size_t i = 0; i < list.size(); ++i) {
penalty_one_line += sub1.Expr(list[i], kPrecedenceLowest,
@@ -706,7 +714,8 @@ int Printer::FunctionCall(const FunctionCallNode* func_call,
// 2: Starting on same line, broken at commas.
Printer sub2;
InitializeSub(&sub2);
- sub2.stack_.push_back(IndentState(CurrentColumn(), true, false));
+ sub2.stack_.push_back(
+ IndentState(CurrentColumn(), continuation_requires_indent, false));
int penalty_multiline_start_same_line = 0;
for (size_t i = 0; i < list.size(); ++i) {
penalty_multiline_start_same_line += sub2.Expr(
@@ -721,7 +730,8 @@ int Printer::FunctionCall(const FunctionCallNode* func_call,
// 3: Starting on next line, broken at commas.
Printer sub3;
InitializeSub(&sub3);
- sub3.stack_.push_back(IndentState(margin() + kIndentSize * 2, true, false));
+ sub3.stack_.push_back(IndentState(margin() + kIndentSize * 2,
+ continuation_requires_indent, false));
sub3.Newline();
int penalty_multiline_start_next_line = 0;
for (size_t i = 0; i < list.size(); ++i) {
@@ -757,10 +767,13 @@ int Printer::FunctionCall(const FunctionCallNode* func_call,
// No elements, and not forcing newlines, print nothing.
} else {
if (penalty_multiline_start_next_line < penalty_multiline_start_same_line) {
- stack_.push_back(IndentState(margin() + kIndentSize * 2, true, false));
+ stack_.push_back(IndentState(margin() + kIndentSize * 2,
+ continuation_requires_indent,
+ false));
Newline();
} else {
- stack_.push_back(IndentState(CurrentColumn(), true, false));
+ stack_.push_back(
+ IndentState(CurrentColumn(), continuation_requires_indent, false));
}
for (size_t i = 0; i < list.size(); ++i) {
« no previous file with comments | « no previous file | tools/gn/command_format_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698