r257324 - clang-format: [JS] Improve line-flow when calling functions on array literals.

Daniel Jasper via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 11 03:00:59 PST 2016


Author: djasper
Date: Mon Jan 11 05:00:58 2016
New Revision: 257324

URL: http://llvm.org/viewvc/llvm-project?rev=257324&view=rev
Log:
clang-format: [JS] Improve line-flow when calling functions on array literals.

Before:
  return [
    aaaaaaaaaaaaaaaaaaaaaa
  ].aaaaaaa(function() {
     //
   })
   .bbbbbb();

After:
  return [aaaaaaaaaaaaaaaaaaaaaa]
      .aaaaaaa(function() {
	//
      })
      .bbbbbb();

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

Modified: cfe/trunk/lib/Format/ContinuationIndenter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/ContinuationIndenter.cpp?rev=257324&r1=257323&r2=257324&view=diff
==============================================================================
--- cfe/trunk/lib/Format/ContinuationIndenter.cpp (original)
+++ cfe/trunk/lib/Format/ContinuationIndenter.cpp Mon Jan 11 05:00:58 2016
@@ -178,13 +178,15 @@ bool ContinuationIndenter::mustBreak(con
     return true;
 
   unsigned NewLineColumn = getNewLineColumn(State);
-  if (State.Column <= NewLineColumn)
-    return false;
-
   if (Current.isMemberAccess() &&
-      State.Column + getLengthToNextOperator(Current) > Style.ColumnLimit)
+      State.Column + getLengthToNextOperator(Current) > Style.ColumnLimit &&
+      (State.Column > NewLineColumn ||
+       Current.NestingLevel < State.StartOfLineLevel))
     return true;
 
+  if (State.Column <= NewLineColumn)
+    return false;
+
   if (Style.AlwaysBreakBeforeMultilineStrings &&
       (NewLineColumn == State.FirstIndent + Style.ContinuationIndentWidth ||
        Previous.is(tok::comma) || Current.NestingLevel < 2) &&

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=257324&r1=257323&r2=257324&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Mon Jan 11 05:00:58 2016
@@ -530,6 +530,12 @@ TEST_F(FormatTestJS, MultipleFunctionLit
   verifyFormat("getSomeLongPromise()\n"
                "    .then(function(value) { body(); })\n"
                "    .thenCatch(function(error) { body(); });");
+
+  verifyFormat("return [aaaaaaaaaaaaaaaaaaaaaa]\n"
+               "    .aaaaaaa(function() {\n"
+               "      //\n"
+               "    })\n"
+               "    .bbbbbb();");
 }
 
 TEST_F(FormatTestJS, ArrowFunctions) {




More information about the cfe-commits mailing list