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

2017-06-23 Thread Andrew Stone via Phabricator via cfe-commits
thatguystone closed this revision.
thatguystone added a comment.

A similar fix was accepted in https://reviews.llvm.org/D33857


https://reviews.llvm.org/D31575



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2017-04-01 Thread Andrew Stone via Phabricator via cfe-commits
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;
 }


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;
 }
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits