r238909 - clang-format: [JS] More aggressively keep array literals on one line.

Daniel Jasper djasper at google.com
Wed Jun 3 01:57:39 PDT 2015


Author: djasper
Date: Wed Jun  3 03:57:36 2015
New Revision: 238909

URL: http://llvm.org/viewvc/llvm-project?rev=238909&view=rev
Log:
clang-format: [JS] More aggressively keep array literals on one line.

Before:
  var aaaaa: List<SomeThing> = [
    new SomeThingAAAAAAAAAAAA(),
    new SomeThingBBBBBBBBB()
  ];

After:
  var aaaaa: List<SomeThing> =
      [new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()];

Modified:
    cfe/trunk/lib/Format/TokenAnnotator.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/TokenAnnotator.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/TokenAnnotator.cpp?rev=238909&r1=238908&r2=238909&view=diff
==============================================================================
--- cfe/trunk/lib/Format/TokenAnnotator.cpp (original)
+++ cfe/trunk/lib/Format/TokenAnnotator.cpp Wed Jun  3 03:57:36 2015
@@ -1627,7 +1627,8 @@ unsigned TokenAnnotator::splitPenalty(co
     // Slightly prefer formatting local lambda definitions like functions.
     if (Right.is(TT_LambdaLSquare) && Left.is(tok::equal))
       return 50;
-    if (!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare))
+    if (!Right.isOneOf(TT_ObjCMethodExpr, TT_LambdaLSquare,
+                       TT_ArrayInitializerLSquare))
       return 500;
   }
 

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=238909&r1=238908&r2=238909&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Jun  3 03:57:36 2015
@@ -248,10 +248,9 @@ TEST_F(FormatTestJS, FormatsFreestanding
 }
 
 TEST_F(FormatTestJS, ArrayLiterals) {
-  verifyFormat("var aaaaa: List<SomeThing> = [\n"
-               "  new SomeThingAAAAAAAAAAAA(),\n"
-               "  new SomeThingBBBBBBBBB()\n"
-               "];");
+  verifyFormat(
+      "var aaaaa: List<SomeThing> =\n"
+      "    [new SomeThingAAAAAAAAAAAA(), new SomeThingBBBBBBBBB()];");
   verifyFormat("return [\n"
                "  aaaaaaaaaaaaaaaaaaaaaaaaaaa,\n"
                "  bbbbbbbbbbbbbbbbbbbbbbbbbbb,\n"





More information about the cfe-commits mailing list