New issue
Advanced search Search tips
Note: Color blocks (like or ) mean that a user may not be available. Tooltip shows the reason.

Issue 721496 link

Starred by 1 user

Issue metadata

Status: WontFix
Owner:
Closed: May 2017
Cc:
EstimatedDays: ----
NextAction: ----
OS: ----
Pri: ----
Type: Bug



Sign in to add a comment

clang-format overly indents multi-line array literals

Project Member Reported by isherman@chromium.org, May 11 2017

Issue description

clang-format produced code that (choose all that apply): 
? Doesn't match Chromium style
? Doesn't match blink style
x Riles my finely honed stylistic dander
- No sane human would ever choose

Here's the code before formatting:
  const std::string patterns[] = {
    // Queries with path "/search" need to have the query parameter in either
    // the url parameter or the hash fragment.
    "%s://www.google.com/search?%s=something",
    "%s://www.google.com/search#%s=something",
    "%s://www.google.com/search?name=bob&%s=something",
    "%s://www.google.com/search?name=bob#%s=something",
    "%s://www.google.com/search?name=bob#age=24&%s=thng",
    "%s://www.google.co.uk/search?%s=something",
    // It's actually valid for both to have the query parameter.
    "%s://www.google.com/search?%s=something#q=other",

    // Queries with path "/webhp", "/" or "" need to have the query parameter
    // in the hash fragment.
    "%s://www.google.com/webhp#%s=something",
    "%s://www.google.com/webhp#name=bob&%s=something",
    "%s://www.google.com/webhp?name=bob#%s=something",
    "%s://www.google.com/webhp?name=bob#age=24&%s=thing",

    "%s://www.google.com/#%s=something",
    "%s://www.google.com/#name=bob&%s=something",
    "%s://www.google.com/?name=bob#%s=something",
    "%s://www.google.com/?name=bob#age=24&%s=something",

    "%s://www.google.com#%s=something",
    "%s://www.google.com#name=bob&%s=something",
    "%s://www.google.com?name=bob#%s=something",
    "%s://www.google.com?name=bob#age=24&%s=something",

    // Google subdomain queries.
    "%s://ipv4.google.com/search?%s=something",
    "%s://ipv4.google.com#name=bob&%s=something",
    "%s://ipv6.google.com?name=bob#%s=something",
    "%s://ipv6.google.com?name=bob#age=24&%s=something",

    // Trailing dots in the hosts.
    "%s://www.google.com./#%s=something", "%s://www.google.de./#%s=something",
    "%s://ipv4.google.com./#%s=something",
    "%s://ipv6.google.com./#%s=something"
  };

Here's the code after formatting:
  const std::string patterns[] = {
      // Queries with path "/search" need to have the query parameter in either
      // the url parameter or the hash fragment.
      "%s://www.google.com/search?%s=something",
      "%s://www.google.com/search#%s=something",
      "%s://www.google.com/search?name=bob&%s=something",
      "%s://www.google.com/search?name=bob#%s=something",
      "%s://www.google.com/search?name=bob#age=24&%s=thng",
      "%s://www.google.co.uk/search?%s=something",
      // It's actually valid for both to have the query parameter.
      "%s://www.google.com/search?%s=something#q=other",

      // Queries with path "/webhp", "/" or "" need to have the query parameter
      // in the hash fragment.
      "%s://www.google.com/webhp#%s=something",
      "%s://www.google.com/webhp#name=bob&%s=something",
      "%s://www.google.com/webhp?name=bob#%s=something",
      "%s://www.google.com/webhp?name=bob#age=24&%s=thing",

      "%s://www.google.com/#%s=something",
      "%s://www.google.com/#name=bob&%s=something",
      "%s://www.google.com/?name=bob#%s=something",
      "%s://www.google.com/?name=bob#age=24&%s=something",

      "%s://www.google.com#%s=something",
      "%s://www.google.com#name=bob&%s=something",
      "%s://www.google.com?name=bob#%s=something",
      "%s://www.google.com?name=bob#age=24&%s=something",

      // Google subdomain queries.
      "%s://ipv4.google.com/search?%s=something",
      "%s://ipv4.google.com#name=bob&%s=something",
      "%s://ipv6.google.com?name=bob#%s=something",
      "%s://ipv6.google.com?name=bob#age=24&%s=something",

      // Trailing dots in the hosts.
      "%s://www.google.com./#%s=something", "%s://www.google.de./#%s=something",
      "%s://ipv4.google.com./#%s=something",
      "%s://ipv6.google.com./#%s=something"};

Here's how it ought to look:
  The before case is better, IMO.  Both because it's less indented, and because I'd expect to see the curly brace on the next line.

Code review link for full files/context:
  https://codereview.chromium.org/2861183002/diff/80001/components/google/core/browser/google_util_unittest.cc
 

Comment 1 by thakis@chromium.org, May 11 2017

Status: WontFix (was: Assigned)
To get curl on next line, add a `,` after the last item.

Indent is intentional, since it matches C++ ctor indenting, and C++11 uniform initialization syntax means that {} and () are mostly the same thing for initialization.
Could you improve to format well even when there's no ',' after the last item? Or is it recommended to have it in this case?

Comment 3 by thakis@chromium.org, May 12 2017

Again, that's so that `A a(a, b, c)` and `A a{a, b, c}` get formatter the same way. If you don't want that, add a trailing comma.

Sign in to add a comment