From: Daniel Jasper Date: Fri, 6 Jun 2014 13:49:04 +0000 (+0000) Subject: clang-format: Fix incorrect indentation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b3482791029bb619a7d561d3caa239aa47b60b5f;p=clang clang-format: Fix incorrect indentation. Before (JavaScript example, but can extend to other languages): return { a: 'E', b: function() { return function() { f(); // This is wrong. }; } }; After: return { a: 'E', b: function() { return function() { f(); // This is better. }; } }; git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@210334 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index ba87b87dd0..f497126950 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -1164,7 +1164,8 @@ private: return true; if (NewLine) { - int AdditionalIndent = 0; + int AdditionalIndent = + State.FirstIndent - State.Line->Level * Style.IndentWidth; if (State.Stack.size() < 2 || !State.Stack[State.Stack.size() - 2].JSFunctionInlined) { AdditionalIndent = State.Stack.back().Indent - diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index ddd594bb6e..50fef8d864 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -137,6 +137,14 @@ TEST_F(FormatTestJS, Closures) { " foo();\n" " bar();\n" "}, this);"); + verifyFormat("return {\n" + " a: 'E',\n" + " b: function() {\n" + " return function() {\n" + " f(); //\n" + " };\n" + " }\n" + "};"); verifyFormat("var x = {a: function() { return 1; }};", getGoogleJSStyleWithColumns(38));