gn format: 80-character comment wrapping and reflowing improvements Implement intelligent paragraph reflowing that triggers when lines exceed 80 characters. Heuristics protect URLs, indented code, pragmas, numbered and bulleted lists and preformatted blocks from reflowing. Single-word paths and targets are also isolated. Attention markers like TODO or NOTE also force distinct paragraph breaks. 20 new tests are added to verify all the new behavior against wrapping scenarios seen in Chromium code base. This latest gn format was run on Chromium's build files and verification was done to ensure no pathological formatting anomolies were observed. In addition, ninja output files were compared before and after and found to be identical. Change-Id: I13c4cd196c64c4ad08e5257fb12076b5f120b5c5 Reviewed-on: https://gn-review.googlesource.com/c/gn/+/21820 Reviewed-by: Takuto Ikuta <tikuta@google.com> Reviewed-by: Andrew Grieve <agrieve@google.com> Commit-Queue: Will Harris <wfh@chromium.org> Commit-Queue: Andrew Grieve <agrieve@google.com>
diff --git a/src/gn/command_format.cc b/src/gn/command_format.cc index 9805309..f1ce0df 100644 --- a/src/gn/command_format.cc +++ b/src/gn/command_format.cc
@@ -158,9 +158,7 @@ // Add the current margin (as spaces) to the output. void PrintMargin(); - void TrimAndPrintToken(const Token& token); - - void PrintTrailingCommentsWrapped(const std::vector<Token>& comments); + void PrintTokensWrapped(const std::vector<Token>& comments); void FlushComments(); @@ -316,20 +314,7 @@ output_ += std::string(margin(), ' '); } -void Printer::TrimAndPrintToken(const Token& token) { - std::string trimmed; - TrimWhitespaceASCII(std::string(token.value()), base::TRIM_ALL, &trimmed); - Print(trimmed); -} - -// Assumes that the margin is set to the indent level where the comments should -// be aligned. This doesn't de-wrap, it only wraps. So if a suffix comment -// causes the line to exceed 80 col it will be wrapped, but the subsequent line -// would fit on the then-broken line it will not be merged with it. This is -// partly because it's difficult to implement at this level, but also because -// it can break hand-authored line breaks where they're starting a new paragraph -// or statement. -void Printer::PrintTrailingCommentsWrapped(const std::vector<Token>& comments) { +void Printer::PrintTokensWrapped(const std::vector<Token>& comments) { bool have_empty_line = true; auto start_next_line = [this, &have_empty_line]() { Trim(); @@ -337,38 +322,158 @@ PrintMargin(); have_empty_line = true; }; - for (const auto& c : comments) { - if (!have_empty_line) { - start_next_line(); - } + // Group consecutive comment lines into paragraphs. A paragraph is reflowed + // if any line exceeds the maximum width. Special lines (e.g. URLs, lists, + // preformatted text) are kept in their own paragraphs and never reflowed. + struct Paragraph { + std::vector<Token> tokens; + bool should_reflow = false; + bool is_preformatted = false; + }; + std::vector<Paragraph> paragraphs; + Paragraph current_paragraph; + + auto flush_paragraph = [&]() { + if (!current_paragraph.tokens.empty()) { + paragraphs.push_back(current_paragraph); + current_paragraph = Paragraph(); + } + }; + + bool in_preformatted_block = false; + + for (const auto& c : comments) { std::string trimmed; TrimWhitespaceASCII(std::string(c.value()), base::TRIM_ALL, &trimmed); - if (margin() + trimmed.size() <= kMaximumWidth) { - Print(trimmed); - have_empty_line = false; + bool is_empty = trimmed == "#"; + if (is_empty) { + in_preformatted_block = false; + } + + bool is_indented = c.value().starts_with("# "); + bool has_url = trimmed.find("http://") != std::string::npos || + trimmed.find("https://") != std::string::npos; + bool is_list = false; + if (trimmed.starts_with("# ") && trimmed.length() >= 4) { + if (trimmed[2] == '-' || trimmed[2] == '*') { + is_list = trimmed[3] == ' '; + } else if (isdigit(trimmed[2])) { + size_t i = 3; + while (i < trimmed.length() && isdigit(trimmed[i])) + i++; + if (i < trimmed.length() && trimmed[i] == '.') + i++; + is_list = i < trimmed.length() && trimmed[i] == ' '; + } + } + bool is_pragma = trimmed.find("# NOSORT") != std::string::npos || + trimmed.find("# KEEPDUPS") != std::string::npos; + + std::string text_only = trimmed.length() > 1 ? trimmed.substr(1) : ""; + TrimWhitespaceASCII(text_only, base::TRIM_ALL, &text_only); + + // A single word (e.g. a long file path) should not be joined with other + // lines, as it often represents a vertical list of items. + bool is_single_word = + !text_only.empty() && text_only.find(' ') == std::string::npos && + (text_only.find('/') != std::string::npos || + text_only.find(':') != std::string::npos); + + // Attention markers start a new paragraph to ensure they remain visible. + bool is_attention_marker = + text_only.starts_with("TODO") || text_only.starts_with("NOTE") || + text_only.starts_with("WARNING") || text_only.starts_with("FIXME"); + + if (is_attention_marker) { + flush_paragraph(); + } + + bool is_special = is_indented || has_url || is_empty || is_list || + is_pragma || is_single_word || in_preformatted_block; + + if (is_special) { + flush_paragraph(); + Paragraph p; + p.tokens.push_back(c); + p.should_reflow = false; + p.is_preformatted = in_preformatted_block || is_single_word || + is_indented || has_url || is_list || is_pragma; + paragraphs.push_back(p); } else { + if (margin() + trimmed.size() > kMaximumWidth) { + current_paragraph.should_reflow = true; + } + current_paragraph.tokens.push_back(c); + } + + // If a line ends with a colon, treat subsequent lines as preformatted + // until an empty comment line is encountered. + if (trimmed.ends_with(':')) { + in_preformatted_block = true; + } + } + flush_paragraph(); + + for (const auto& p : paragraphs) { + if (p.should_reflow) { + // Combine all tokens in the paragraph into a single list of words. + std::vector<std::string> words; + for (const auto& t : p.tokens) { + std::string trimmed; + TrimWhitespaceASCII(std::string(t.value()), base::TRIM_ALL, &trimmed); + std::vector<std::string> line_words = base::SplitString( + trimmed, " ", base::WhitespaceHandling::TRIM_WHITESPACE, + base::SplitResult::SPLIT_WANT_NONEMPTY); + if (words.empty()) { + words.push_back("#"); + } + for (const auto& w : line_words) { + if (w != "#") + words.push_back(w); + } + } + + if (!have_empty_line) + start_next_line(); + + // Output words, wrapping to the next line when the maximum width is + // reached. bool continuation = false; - std::vector<std::string> split_on_spaces = base::SplitString( - c.value(), " ", base::WhitespaceHandling::TRIM_WHITESPACE, - base::SplitResult::SPLIT_WANT_NONEMPTY); - for (size_t j = 0; j < split_on_spaces.size(); ++j) { + for (size_t j = 0; j < words.size(); ++j) { if (have_empty_line && continuation) { Print("# "); + have_empty_line = false; + } else if (j > 0) { + Print(" "); } - Print(split_on_spaces[j]); - Print(" "); - if (split_on_spaces[j] != "#") { + Print(words[j]); + + if (words[j] != "#") { have_empty_line = false; } - if (!have_empty_line && - (j < split_on_spaces.size() - 1 && - CurrentColumn() + split_on_spaces[j + 1].size() > kMaximumWidth)) { + + if (!have_empty_line && j < words.size() - 1 && + CurrentColumn() + 1 + words[j + 1].size() > kMaximumWidth) { start_next_line(); continuation = true; } } + } else { + // For paragraphs that do not require reflowing (e.g. special lines or + // paragraphs where all lines fit within the maximum width), output them + // exactly as authored. + for (const auto& c : p.tokens) { + if (!have_empty_line) { + start_next_line(); + } + + std::string trimmed; + TrimWhitespaceASCII(std::string(c.value()), base::TRIM_ALL, &trimmed); + Print(trimmed); + have_empty_line = false; + } } } } @@ -378,7 +483,7 @@ if (node->comments() && !node->comments()->suffix().empty()) { Print(" "); stack_.push_back(IndentState(CurrentColumn(), false, false)); - PrintTrailingCommentsWrapped(node->comments()->suffix()); + PrintTokensWrapped(node->comments()->suffix()); stack_.pop_back(); } } @@ -389,7 +494,7 @@ // Save the margin, and temporarily set it to where the first comment // starts so that multiple suffix comments are vertically aligned. stack_.push_back(IndentState(CurrentColumn(), false, false)); - PrintTrailingCommentsWrapped(comments_); + PrintTokensWrapped(comments_); stack_.pop_back(); comments_.clear(); } @@ -705,8 +810,8 @@ const BlockNode* block = root->AsBlock(); if (block->comments()) { - for (const auto& c : block->comments()->before()) { - TrimAndPrintToken(c); + if (!block->comments()->before().empty()) { + PrintTokensWrapped(block->comments()->before()); Newline(); } } @@ -724,8 +829,8 @@ // However, because it's a general expression handler, it doesn't insert // the newline itself, which only happens between block statements. So, // the after are handled explicitly here. - for (const auto& c : stmt->comments()->after()) { - TrimAndPrintToken(c); + if (!stmt->comments()->after().empty()) { + PrintTokensWrapped(stmt->comments()->after()); Newline(); } } @@ -744,8 +849,8 @@ // then the two comments were originally separate, so keep them that way. Newline(); } - for (const auto& c : block->comments()->after()) { - TrimAndPrintToken(c); + if (!block->comments()->after().empty()) { + PrintTokensWrapped(block->comments()->after()); Newline(); } } @@ -797,8 +902,8 @@ Print("\n"); // We're printing a line comment, so we need to be at the current margin. PrintMargin(); - for (const auto& c : root->comments()->before()) { - TrimAndPrintToken(c); + if (!root->comments()->before().empty()) { + PrintTokensWrapped(root->comments()->before()); Newline(); } } @@ -998,7 +1103,7 @@ Print(unaryop->op().value()); Expr(unaryop->operand(), kPrecedenceUnary, std::string()); } else if (const BlockCommentNode* block_comment = root->AsBlockComment()) { - Print(block_comment->comment().value()); + PrintTokensWrapped({block_comment->comment()}); } else if (const EndNode* end = root->AsEnd()) { Print(end->value().value()); } else { @@ -1076,10 +1181,8 @@ if (end->comments() && !end->comments()->before().empty()) { if (list.size() >= 2) Newline(); - for (const auto& c : end->comments()->before()) { - Newline(); - TrimAndPrintToken(c); - } + Newline(); + PrintTokensWrapped(end->comments()->before()); } stack_.pop_back(); @@ -1239,10 +1342,8 @@ if (end->comments() && !end->comments()->before().empty()) { if (!list.empty()) Newline(); - for (const auto& c : end->comments()->before()) { - Newline(); - TrimAndPrintToken(c); - } + Newline(); + PrintTokensWrapped(end->comments()->before()); Newline(); } stack_.pop_back();
diff --git a/src/gn/command_format_unittest.cc b/src/gn/command_format_unittest.cc index 645ec27..0149cbc 100644 --- a/src/gn/command_format_unittest.cc +++ b/src/gn/command_format_unittest.cc
@@ -138,3 +138,23 @@ FORMAT_TEST(083) FORMAT_TEST(084) FORMAT_TEST(085) +FORMAT_TEST(086) +FORMAT_TEST(087) +FORMAT_TEST(088) +FORMAT_TEST(089) +FORMAT_TEST(090) +FORMAT_TEST(091) +FORMAT_TEST(092) +FORMAT_TEST(093) +FORMAT_TEST(094) +FORMAT_TEST(095) +FORMAT_TEST(096) +FORMAT_TEST(097) +FORMAT_TEST(098) +FORMAT_TEST(099) +FORMAT_TEST(100) +FORMAT_TEST(101) +FORMAT_TEST(102) +FORMAT_TEST(103) +FORMAT_TEST(104) +FORMAT_TEST(105)
diff --git a/src/gn/format_test_data/086.gn b/src/gn/format_test_data/086.gn new file mode 100644 index 0000000..d1ab899 --- /dev/null +++ b/src/gn/format_test_data/086.gn
@@ -0,0 +1,11 @@ +# This is a very very very very very very very very very very very very very very very very very very very very very very very very very long comment. +# Another line. +executable("foo") { + sources = [ "foo.cc" ] + + # And here is an indented comment that is also extremely long and needs to be wrapped properly at the 80 character limit. + if (is_win) { + # This is a block comment in an inner scope. + # It also has a long line that exceeds the 80 column limit and should be wrapped to the next line keeping the same indentation. + } +}
diff --git a/src/gn/format_test_data/086.golden b/src/gn/format_test_data/086.golden new file mode 100644 index 0000000..8ff561b --- /dev/null +++ b/src/gn/format_test_data/086.golden
@@ -0,0 +1,14 @@ +# This is a very very very very very very very very very very very very very +# very very very very very very very very very very very very long comment. +# Another line. +executable("foo") { + sources = [ "foo.cc" ] + + # And here is an indented comment that is also extremely long and needs to be + # wrapped properly at the 80 character limit. + if (is_win) { + # This is a block comment in an inner scope. It also has a long line that + # exceeds the 80 column limit and should be wrapped to the next line keeping + # the same indentation. + } +}
diff --git a/src/gn/format_test_data/087.gn b/src/gn/format_test_data/087.gn new file mode 100644 index 0000000..0e9110f --- /dev/null +++ b/src/gn/format_test_data/087.gn
@@ -0,0 +1 @@ +# This is a very very very very very very very very very very very very very very very very very very very very very very very very very long comment with extra spaces. \ No newline at end of file
diff --git a/src/gn/format_test_data/087.golden b/src/gn/format_test_data/087.golden new file mode 100644 index 0000000..f882a2b --- /dev/null +++ b/src/gn/format_test_data/087.golden
@@ -0,0 +1,3 @@ +# This is a very very very very very very very very very very very very very +# very very very very very very very very very very very very long comment with +# extra spaces.
diff --git a/src/gn/format_test_data/088.gn b/src/gn/format_test_data/088.gn new file mode 100644 index 0000000..31a0b8a --- /dev/null +++ b/src/gn/format_test_data/088.gn
@@ -0,0 +1 @@ +# This is a short comment with extra spaces. \ No newline at end of file
diff --git a/src/gn/format_test_data/088.golden b/src/gn/format_test_data/088.golden new file mode 100644 index 0000000..b3635ca --- /dev/null +++ b/src/gn/format_test_data/088.golden
@@ -0,0 +1 @@ +# This is a short comment with extra spaces.
diff --git a/src/gn/format_test_data/089.gn b/src/gn/format_test_data/089.gn new file mode 100644 index 0000000..f85de6f --- /dev/null +++ b/src/gn/format_test_data/089.gn
@@ -0,0 +1 @@ +# This is a very very very very very very very very very very long URL: https://www.google.com/very/long/url/that/exceeds/the/eighty/character/limit/for/a/line/length
diff --git a/src/gn/format_test_data/089.golden b/src/gn/format_test_data/089.golden new file mode 100644 index 0000000..f85de6f --- /dev/null +++ b/src/gn/format_test_data/089.golden
@@ -0,0 +1 @@ +# This is a very very very very very very very very very very long URL: https://www.google.com/very/long/url/that/exceeds/the/eighty/character/limit/for/a/line/length
diff --git a/src/gn/format_test_data/090.gn b/src/gn/format_test_data/090.gn new file mode 100644 index 0000000..821376e --- /dev/null +++ b/src/gn/format_test_data/090.gn
@@ -0,0 +1,3 @@ +executable("foo") { + sources = [ "foo.cc" ] # This is a very very very very very very very very very very very very very very very very very very very very very very very very very long trailing comment. +} \ No newline at end of file
diff --git a/src/gn/format_test_data/090.golden b/src/gn/format_test_data/090.golden new file mode 100644 index 0000000..54943fb --- /dev/null +++ b/src/gn/format_test_data/090.golden
@@ -0,0 +1,6 @@ +executable("foo") { + sources = + [ "foo.cc" ] # This is a very very very very very very very very very + # very very very very very very very very very very very + # very very very very very long trailing comment. +}
diff --git a/src/gn/format_test_data/091.gn b/src/gn/format_test_data/091.gn new file mode 100644 index 0000000..ecd1b17 --- /dev/null +++ b/src/gn/format_test_data/091.gn
@@ -0,0 +1,3 @@ +executable("foo") { + sources = [ "foo.cc" ] # This is a very very very very very very very very very very very very very very very very very very very very very very very very very long URL: https://www.google.com/very/long/url/that/exceeds/the/eighty/character/limit/for/a/line/length +}
diff --git a/src/gn/format_test_data/091.golden b/src/gn/format_test_data/091.golden new file mode 100644 index 0000000..d4febd0 --- /dev/null +++ b/src/gn/format_test_data/091.golden
@@ -0,0 +1,3 @@ +executable("foo") { + sources = [ "foo.cc" ] # This is a very very very very very very very very very very very very very very very very very very very very very very very very very long URL: https://www.google.com/very/long/url/that/exceeds/the/eighty/character/limit/for/a/line/length +}
diff --git a/src/gn/format_test_data/092.gn b/src/gn/format_test_data/092.gn new file mode 100644 index 0000000..82d4fa4 --- /dev/null +++ b/src/gn/format_test_data/092.gn
@@ -0,0 +1,3 @@ +executable("foo") { + sources = [ "foo.cc" ] # This is a very very very very very very very very very very very very very very very very very very very very very very very very very long trailing comment with extra spaces. +} \ No newline at end of file
diff --git a/src/gn/format_test_data/092.golden b/src/gn/format_test_data/092.golden new file mode 100644 index 0000000..c5aad2f --- /dev/null +++ b/src/gn/format_test_data/092.golden
@@ -0,0 +1,6 @@ +executable("foo") { + sources = [ "foo.cc" ] # This is a very very very very very very very very + # very very very very very very very very very very + # very very very very very very very long trailing + # comment with extra spaces. +}
diff --git a/src/gn/format_test_data/093.gn b/src/gn/format_test_data/093.gn new file mode 100644 index 0000000..b3dead1 --- /dev/null +++ b/src/gn/format_test_data/093.gn
@@ -0,0 +1 @@ +this_is_a_very_long_variable_name_that_exceeds_eighty_characters_all_by_itself_without_any_spaces = true # This is a very very very very very very very very very very very very very very very very very very very very very very very very very long trailing comment.
diff --git a/src/gn/format_test_data/093.golden b/src/gn/format_test_data/093.golden new file mode 100644 index 0000000..88a9b08 --- /dev/null +++ b/src/gn/format_test_data/093.golden
@@ -0,0 +1,31 @@ +this_is_a_very_long_variable_name_that_exceeds_eighty_characters_all_by_itself_without_any_spaces = true # This + # is + # a + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # very + # long + # trailing + # comment.
diff --git a/src/gn/format_test_data/094.gn b/src/gn/format_test_data/094.gn new file mode 100644 index 0000000..2e2c3ca --- /dev/null +++ b/src/gn/format_test_data/094.gn
@@ -0,0 +1,3 @@ +# Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor and +# incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud +# exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute a /
diff --git a/src/gn/format_test_data/094.golden b/src/gn/format_test_data/094.golden new file mode 100644 index 0000000..e8a0030 --- /dev/null +++ b/src/gn/format_test_data/094.golden
@@ -0,0 +1,4 @@ +# Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor +# and incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis +# nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. +# Duis aute a /
diff --git a/src/gn/format_test_data/095.gn b/src/gn/format_test_data/095.gn new file mode 100644 index 0000000..d954df5 --- /dev/null +++ b/src/gn/format_test_data/095.gn
@@ -0,0 +1 @@ +# RSP manipulation due to https://bugs.an_foo_b.com/p/gn/issues/detail?id=249
diff --git a/src/gn/format_test_data/095.golden b/src/gn/format_test_data/095.golden new file mode 100644 index 0000000..d954df5 --- /dev/null +++ b/src/gn/format_test_data/095.golden
@@ -0,0 +1 @@ +# RSP manipulation due to https://bugs.an_foo_b.com/p/gn/issues/detail?id=249
diff --git a/src/gn/format_test_data/096.gn b/src/gn/format_test_data/096.gn new file mode 100644 index 0000000..065108a --- /dev/null +++ b/src/gn/format_test_data/096.gn
@@ -0,0 +1,7 @@ +if (true) { + if (true) { + if (true) { + pgo_data_path = "//android_web_foo/tools/orderfiles/arm64/pgo_profile.arm64.profdata" + } + } +}
diff --git a/src/gn/format_test_data/096.golden b/src/gn/format_test_data/096.golden new file mode 100644 index 0000000..513adb7 --- /dev/null +++ b/src/gn/format_test_data/096.golden
@@ -0,0 +1,8 @@ +if (true) { + if (true) { + if (true) { + pgo_data_path = + "//android_web_foo/tools/orderfiles/arm64/pgo_profile.arm64.profdata" + } + } +}
diff --git a/src/gn/format_test_data/097.gn b/src/gn/format_test_data/097.gn new file mode 100644 index 0000000..7beacc1 --- /dev/null +++ b/src/gn/format_test_data/097.gn
@@ -0,0 +1,2 @@ +# problematic for FooBar because of targets like +# //third_party/an_foo_b/src/trace_processor/an_foo_b_sql/stdlib:stdlib_generated_file
diff --git a/src/gn/format_test_data/097.golden b/src/gn/format_test_data/097.golden new file mode 100644 index 0000000..7beacc1 --- /dev/null +++ b/src/gn/format_test_data/097.golden
@@ -0,0 +1,2 @@ +# problematic for FooBar because of targets like +# //third_party/an_foo_b/src/trace_processor/an_foo_b_sql/stdlib:stdlib_generated_file
diff --git a/src/gn/format_test_data/098.gn b/src/gn/format_test_data/098.gn new file mode 100644 index 0000000..eae4aec --- /dev/null +++ b/src/gn/format_test_data/098.gn
@@ -0,0 +1,3 @@ +# Copyright 2013 The Chromium Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file.
diff --git a/src/gn/format_test_data/098.golden b/src/gn/format_test_data/098.golden new file mode 100644 index 0000000..eae4aec --- /dev/null +++ b/src/gn/format_test_data/098.golden
@@ -0,0 +1,3 @@ +# Copyright 2013 The Chromium Authors +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file.
diff --git a/src/gn/format_test_data/099.gn b/src/gn/format_test_data/099.gn new file mode 100644 index 0000000..a792567 --- /dev/null +++ b/src/gn/format_test_data/099.gn
@@ -0,0 +1,8 @@ +if (is_android) { + if (true) { + # lorem_ips is a dolor of amet_ that are being elit_ipsum by almost every tempor and + # library in Chromium, adding new amet modules here means that all elit_amet will be + # impacted (eg: This could have severe consequences as Nullam can't depend on Ipsum / + # AndroidX). + } +}
diff --git a/src/gn/format_test_data/099.golden b/src/gn/format_test_data/099.golden new file mode 100644 index 0000000..4f0ea1c --- /dev/null +++ b/src/gn/format_test_data/099.golden
@@ -0,0 +1,8 @@ +if (is_android) { + if (true) { + # lorem_ips is a dolor of amet_ that are being elit_ipsum by almost every + # tempor and library in Chromium, adding new amet modules here means that + # all elit_amet will be impacted (eg: This could have severe consequences as + # Nullam can't depend on Ipsum / AndroidX). + } +}
diff --git a/src/gn/format_test_data/100.gn b/src/gn/format_test_data/100.gn new file mode 100644 index 0000000..e323566 --- /dev/null +++ b/src/gn/format_test_data/100.gn
@@ -0,0 +1,3 @@ +# To regenerate this list, run: +# sed -i '/^[^#][^[]*$/d' an_foo_java_resources.gni +# (for f in $(find java/res/*/ -type f); do echo ' "'$f'",'; done; echo ']') >> an_foo_java_resources.gni
diff --git a/src/gn/format_test_data/100.golden b/src/gn/format_test_data/100.golden new file mode 100644 index 0000000..e323566 --- /dev/null +++ b/src/gn/format_test_data/100.golden
@@ -0,0 +1,3 @@ +# To regenerate this list, run: +# sed -i '/^[^#][^[]*$/d' an_foo_java_resources.gni +# (for f in $(find java/res/*/ -type f); do echo ' "'$f'",'; done; echo ']') >> an_foo_java_resources.gni
diff --git a/src/gn/format_test_data/101.gn b/src/gn/format_test_data/101.gn new file mode 100644 index 0000000..0880415 --- /dev/null +++ b/src/gn/format_test_data/101.gn
@@ -0,0 +1,12 @@ +group("foo") { + if (true) { + if (true) { + # TODO(crbug.com/123456789): Remove this circular dependency once the following + # headers get componentized: + # a/b/custom_handlers/protocol_handler_registry_factory.h + # a/b/profiles/profile_io_data.h + # a/b/history/top_sites_factory.h + # a/b/history_embeddings/history_embeddings_service_factory.h + } + } +}
diff --git a/src/gn/format_test_data/101.golden b/src/gn/format_test_data/101.golden new file mode 100644 index 0000000..7a9757e --- /dev/null +++ b/src/gn/format_test_data/101.golden
@@ -0,0 +1,12 @@ +group("foo") { + if (true) { + if (true) { + # TODO(crbug.com/123456789): Remove this circular dependency once the + # following headers get componentized: + # a/b/custom_handlers/protocol_handler_registry_factory.h + # a/b/profiles/profile_io_data.h + # a/b/history/top_sites_factory.h + # a/b/history_embeddings/history_embeddings_service_factory.h + } + } +}
diff --git a/src/gn/format_test_data/102.gn b/src/gn/format_test_data/102.gn new file mode 100644 index 0000000..4b5c188 --- /dev/null +++ b/src/gn/format_test_data/102.gn
@@ -0,0 +1,8 @@ +if (true) { + if (true) { + # you are adding //third_party/a_foo_b_deps:a_foo_b_support_*, use the a_foo_bx + # version of the dep instead. + # TODO(b/123456789): Use per-feature -keep rules in R8 once supported, then + # this can be removed. + } +}
diff --git a/src/gn/format_test_data/102.golden b/src/gn/format_test_data/102.golden new file mode 100644 index 0000000..903be42 --- /dev/null +++ b/src/gn/format_test_data/102.golden
@@ -0,0 +1,8 @@ +if (true) { + if (true) { + # you are adding //third_party/a_foo_b_deps:a_foo_b_support_*, use the + # a_foo_bx version of the dep instead. + # TODO(b/123456789): Use per-feature -keep rules in R8 once supported, then + # this can be removed. + } +}
diff --git a/src/gn/format_test_data/103.gn b/src/gn/format_test_data/103.gn new file mode 100644 index 0000000..84265d8 --- /dev/null +++ b/src/gn/format_test_data/103.gn
@@ -0,0 +1,6 @@ +# NOTE: This target is separated from :browser as +# //components/safe_foo_bar_/content/browser/triggers, which this depends on, depends +# on :browser. +# TODO(crbug.com/12345678): Consider folding all of three these together into +# :browser, along with the other browser process code in +# //components/safe_foo_bar_/content.
diff --git a/src/gn/format_test_data/103.golden b/src/gn/format_test_data/103.golden new file mode 100644 index 0000000..f0f836d --- /dev/null +++ b/src/gn/format_test_data/103.golden
@@ -0,0 +1,6 @@ +# NOTE: This target is separated from :browser as +# //components/safe_foo_bar_/content/browser/triggers, which this depends on, +# depends on :browser. +# TODO(crbug.com/12345678): Consider folding all of three these together into +# :browser, along with the other browser process code in +# //components/safe_foo_bar_/content.
diff --git a/src/gn/format_test_data/104.gn b/src/gn/format_test_data/104.gn new file mode 100644 index 0000000..2bf5199 --- /dev/null +++ b/src/gn/format_test_data/104.gn
@@ -0,0 +1,4 @@ +# These sources depend on targets from "//content/browser", which means they can +# only be loaded on A_Foo builds. +# NOTE: If/when targets used on iOS are refactored into a separate BUILD file, +# this check can be removed.
diff --git a/src/gn/format_test_data/104.golden b/src/gn/format_test_data/104.golden new file mode 100644 index 0000000..2bf5199 --- /dev/null +++ b/src/gn/format_test_data/104.golden
@@ -0,0 +1,4 @@ +# These sources depend on targets from "//content/browser", which means they can +# only be loaded on A_Foo builds. +# NOTE: If/when targets used on iOS are refactored into a separate BUILD file, +# this check can be removed.
diff --git a/src/gn/format_test_data/105.gn b/src/gn/format_test_data/105.gn new file mode 100644 index 0000000..76e4854 --- /dev/null +++ b/src/gn/format_test_data/105.gn
@@ -0,0 +1,7 @@ +# This is a very long line that should normally reflow but we want to make sure it does not merge with the list item below it. +# 1. This is a list item. +# 10. This is a multi-digit list item. +# 100 This is a multi-digit list item without a dot. +# - This is a bullet list. +# * This is another bullet list. +# This is another very long line that should also reflow but should not merge with the list item above it.
diff --git a/src/gn/format_test_data/105.golden b/src/gn/format_test_data/105.golden new file mode 100644 index 0000000..60b6fc6 --- /dev/null +++ b/src/gn/format_test_data/105.golden
@@ -0,0 +1,9 @@ +# This is a very long line that should normally reflow but we want to make sure +# it does not merge with the list item below it. +# 1. This is a list item. +# 10. This is a multi-digit list item. +# 100 This is a multi-digit list item without a dot. +# - This is a bullet list. +# * This is another bullet list. +# This is another very long line that should also reflow but should not merge +# with the list item above it.