r210334 - clang-format: Fix incorrect indentation.
Daniel Jasper
djasper at google.com
Fri Jun 6 06:49:04 PDT 2014
Author: djasper
Date: Fri Jun 6 08:49:04 2014
New Revision: 210334
URL: http://llvm.org/viewvc/llvm-project?rev=210334&view=rev
Log:
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.
};
}
};
Modified:
cfe/trunk/lib/Format/Format.cpp
cfe/trunk/unittests/Format/FormatTestJS.cpp
Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=210334&r1=210333&r2=210334&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Fri Jun 6 08:49:04 2014
@@ -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 -
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=210334&r1=210333&r2=210334&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Fri Jun 6 08:49:04 2014
@@ -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));
More information about the cfe-commits
mailing list