]> granicus.if.org Git - clang/commitdiff
clang-format: Fix incorrect indentation.
authorDaniel Jasper <djasper@google.com>
Fri, 6 Jun 2014 13:49:04 +0000 (13:49 +0000)
committerDaniel Jasper <djasper@google.com>
Fri, 6 Jun 2014 13:49:04 +0000 (13:49 +0000)
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

lib/Format/Format.cpp
unittests/Format/FormatTestJS.cpp

index ba87b87dd0d46e04e4dda73d7b95f7617dbd1004..f497126950d0210f4272812172ee4d4639d41119 100644 (file)
@@ -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 -
index ddd594bb6e702bd86fb556b17fafb6db8c073154..50fef8d86463da5f88f562989e4f35dfdc60b149 100644 (file)
@@ -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));