diff options
author | Martin Probst <martin@probst.io> | 2017-06-06 12:38:29 +0000 |
---|---|---|
committer | Martin Probst <martin@probst.io> | 2017-06-06 12:38:29 +0000 |
commit | 069779a6e1f2cf1c0512c115c3c99359ac865039 (patch) | |
tree | e155f3a327133c3ff860cd53eaee283721083059 /lib/Format | |
parent | 84aa45a35c5cb99743e562fe81cd74c05458f1e6 (diff) |
clang-format: [JS] Correctly Indent Nested JavaScript Literals.
Nested literals are sometimes only indented by 2 spaces, instead of
respecting the IndentWidth option.
There are existing unit tests (FormatTestJS.ArrayLiterals) that only
pass because the style used to test them uses an IndentWidth of 2.
This change removes the magic 2 and always uses the IndentWidth.
I've added 6 tests. The first 4 of these tests fail before this change,
while the last 2 already pass, but were added just to make sure it the
change works with all types of braces.
Patch originally by Jared Neil, thanks!
Differential Revision: https://reviews.llvm.org/D33857
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@304791 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Format')
-rw-r--r-- | lib/Format/ContinuationIndenter.cpp | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/lib/Format/ContinuationIndenter.cpp b/lib/Format/ContinuationIndenter.cpp index ae1af753bf..387923031f 100644 --- a/lib/Format/ContinuationIndenter.cpp +++ b/lib/Format/ContinuationIndenter.cpp @@ -1036,8 +1036,8 @@ void ContinuationIndenter::moveStatePastScopeOpener(LineState &State, State.Stack.back().NestedBlockIndent); 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 = Style.IndentWidth + + std::min(State.Column, State.Stack.back().NestedBlockIndent); } else { NewIndent = State.Stack.back().LastSpace + Style.ContinuationIndentWidth; } |