From: Daniel Jasper Date: Fri, 20 Nov 2015 16:18:42 +0000 (+0000) Subject: clang-format: [JS] Properly add a space after "in" in for loops. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=53b1a37ee09915ea3e70ff2061af9d5bb19428cc;p=clang clang-format: [JS] Properly add a space after "in" in for loops. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@253672 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Format/TokenAnnotator.cpp b/lib/Format/TokenAnnotator.cpp index 751b070cdf..171ecc41d7 100644 --- a/lib/Format/TokenAnnotator.cpp +++ b/lib/Format/TokenAnnotator.cpp @@ -1955,7 +1955,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line, Left.isOneOf(Keywords.kw_returns, Keywords.kw_option)) return true; } else if (Style.Language == FormatStyle::LK_JavaScript) { - if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, TT_JsFatArrow)) + if (Left.isOneOf(Keywords.kw_let, Keywords.kw_var, TT_JsFatArrow, + Keywords.kw_in)) return true; if (Right.isOneOf(TT_JsTypeColon, TT_JsTypeOptionalQuestion)) return false; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 9be375243c..56a91442f9 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -545,6 +545,11 @@ TEST_F(FormatTestJS, ReturnStatements) { "}"); } +TEST_F(FormatTestJS, ForLoops) { + verifyFormat("for (var i in [2, 3]) {\n" + "}"); +} + TEST_F(FormatTestJS, AutomaticSemicolonInsertion) { // The following statements must not wrap, as otherwise the program meaning // would change due to automatic semicolon insertion.