]> granicus.if.org Git - clang/commitdiff
clang-format: Make it very slighly more expensive to wrap between "= {".
authorDaniel Jasper <djasper@google.com>
Tue, 14 Mar 2017 00:40:32 +0000 (00:40 +0000)
committerDaniel Jasper <djasper@google.com>
Tue, 14 Mar 2017 00:40:32 +0000 (00:40 +0000)
This prevents unwanted fallout from r296664. Specifically in proto formatting,
this changed:
  optional Aaaaaaaa aaaaaaaa = 12 [
    (aaa) = aaaa,
    (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {
      aaaaaaaaaaaaaaaaa: true,
      aaaaaaaaaaaaaaaa: true
    }
  ];

Into:
  optional Aaaaaaaa aaaaaaaa = 12 [
    (aaa) = aaaa,
    (bbbbbbbbbbbbbbbbbbbbbbbbbb) =
        {aaaaaaaaaaaaaaaaa: true, aaaaaaaaaaaaaaaa: true}
  ];

Which is considered less readable. Generally, it seems preferable to
format such dict literals as blocks rather than contract them to one
line.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@297696 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/TokenAnnotator.cpp
unittests/Format/FormatTestProto.cpp

index ed9788d7476f740ba98d2d65768e2124aa9d1d93..228425bc4732eb1db87a6f5b126d1f2c39719352 100644 (file)
@@ -1976,7 +1976,7 @@ unsigned TokenAnnotator::splitPenalty(const AnnotatedLine &Line,
   if (Right.is(TT_LambdaArrow))
     return 110;
   if (Left.is(tok::equal) && Right.is(tok::l_brace))
-    return 150;
+    return 160;
   if (Left.is(TT_CastRParen))
     return 100;
   if (Left.is(tok::coloncolon) ||
index 41d210ac7cd71df4c07f1b165717c01295d68003..d174c65a1f32ddd433cf5f1794d19e774ab96ce0 100644 (file)
@@ -138,6 +138,13 @@ TEST_F(FormatTestProto, MessageFieldAttributes) {
   verifyFormat("optional string test = 1 [default =\n"
                "                              \"test\"\n"
                "                              \"test\"];");
+  verifyFormat("optional Aaaaaaaa aaaaaaaa = 12 [\n"
+               "  (aaa) = aaaa,\n"
+               "  (bbbbbbbbbbbbbbbbbbbbbbbbbb) = {\n"
+               "    aaaaaaaaaaaaaaaaa: true,\n"
+               "    aaaaaaaaaaaaaaaa: true\n"
+               "  }\n"
+               "];");
 }
 
 TEST_F(FormatTestProto, DoesntWrapFileOptions) {