[PATCH] D31575: [clang-format] Use configured IndentWidth instead of 2

Andrew Stone via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 1 17:28:56 PDT 2017


thatguystone created this revision.
Herald added a subscriber: klimek.

For JS projects that use a IdentWidth other than 2, this was causing the indent to be 2 when creating new objects in arrays.


Repository:
  rL LLVM

https://reviews.llvm.org/D31575

Files:
  lib/Format/ContinuationIndenter.cpp
  unittests/Format/FormatTestJS.cpp


Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -287,6 +287,31 @@
                "};");
 }
 
+TEST_F(FormatTestJS, ContainerLiteralsIndentWidth) {
+  FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+  Style.IndentWidth = 4;
+
+  verifyFormat("return [\n"
+               "    {\n"
+               "        a: 1,\n"
+               "    },\n"
+               "    {\n"
+               "        b: 2,\n"
+               "    },\n"
+               "];",
+               Style);
+  verifyFormat("return {\n"
+               "    nested: {\n"
+               "        values: {\n"
+               "            indent: [\n"
+               "                right,\n"
+               "            ],\n"
+               "        },\n"
+               "    },\n"
+               "};",
+               Style);
+}
+
 TEST_F(FormatTestJS, MethodsInObjectLiterals) {
   verifyFormat("var o = {\n"
                "  value: 'test',\n"
Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -991,7 +991,7 @@
   if (Current.isOneOf(tok::l_brace, TT_ArrayInitializerLSquare)) {
     if (Current.opensBlockOrBlockTypeList(Style)) {
       NewIndent = State.Stack.back().NestedBlockIndent + Style.IndentWidth;
-      NewIndent = std::min(State.Column + 2, NewIndent);
+      NewIndent = std::min(State.Column + Style.IndentWidth, NewIndent);
     } else {
       NewIndent = State.Stack.back().LastSpace + Style.ContinuationIndentWidth;
     }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D31575.93769.patch
Type: text/x-patch
Size: 1721 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170402/b51278e8/attachment.bin>


More information about the cfe-commits mailing list