clang-format overly indents multi-line array literals |
|
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
,
May 12 2017
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?
,
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 |
|
Comment 1 by thakis@chromium.org
, May 11 2017To 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.