From: Daniel Jasper Date: Mon, 11 Jan 2016 11:00:58 +0000 (+0000) Subject: clang-format: [JS] Improve line-flow when calling functions on array literals. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=39aa30ea9781635771723e63f23cfd58dd7d1505;p=clang clang-format: [JS] Improve line-flow when calling functions on array literals. Before: return [ aaaaaaaaaaaaaaaaaaaaaa ].aaaaaaa(function() { // }) .bbbbbb(); After: return [aaaaaaaaaaaaaaaaaaaaaa] .aaaaaaa(function() { // }) .bbbbbb(); git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@257324 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index ff2569d41a..cb5999e60e 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -178,13 +178,15 @@ bool ContinuationIndenter::mustBreak(const LineState &State) { 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) && diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 4e974d7285..9477580016 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -530,6 +530,12 @@ TEST_F(FormatTestJS, MultipleFunctionLiterals) { 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) {