diff options
author | Daniel Jasper <djasper@google.com> | 2014-10-31 17:50:40 +0000 |
---|---|---|
committer | Daniel Jasper <djasper@google.com> | 2014-10-31 17:50:40 +0000 |
commit | f739b0dbfa14492f0fec76bc46bc651529a0eae8 (patch) | |
tree | 8f9b51bc3668ccab9746fd5dbedee4cadf8cfa9d | |
parent | 8a020310b8b2a9d33b327ca9ae2483da8df59876 (diff) | |
download | bcm5719-llvm-f739b0dbfa14492f0fec76bc46bc651529a0eae8.tar.gz bcm5719-llvm-f739b0dbfa14492f0fec76bc46bc651529a0eae8.zip |
clang-format: [js] Updates to Google's JavaScript style.
The style guide is changing..
llvm-svn: 220977
-rw-r--r-- | clang/lib/Format/ContinuationIndenter.cpp | 1 | ||||
-rw-r--r-- | clang/lib/Format/Format.cpp | 2 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTest.cpp | 4 | ||||
-rw-r--r-- | clang/unittests/Format/FormatTestJS.cpp | 33 |
4 files changed, 19 insertions, 21 deletions
diff --git a/clang/lib/Format/ContinuationIndenter.cpp b/clang/lib/Format/ContinuationIndenter.cpp index 41dc09b11dc..0920137870a 100644 --- a/clang/lib/Format/ContinuationIndenter.cpp +++ b/clang/lib/Format/ContinuationIndenter.cpp @@ -664,6 +664,7 @@ unsigned ContinuationIndenter::moveStateToNextToken(LineState &State, if (Current.TokenText == "function") State.Stack.back().JSFunctionInlined = !Newline && Previous && Previous->Type != TT_DictLiteral && + Previous->Type != TT_ConditionalExpr && // If the unnamed function is the only parameter to another function, // we can likely inline it and come up with a good format. (Previous->isNot(tok::l_paren) || Previous->ParameterCount > 1); diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 4f3b86a4a71..300bd626ed8 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -416,7 +416,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.ColumnLimit = 100; GoogleStyle.SpaceAfterCStyleCast = true; } else if (Language == FormatStyle::LK_JavaScript) { - GoogleStyle.BreakBeforeTernaryOperators = false; + GoogleStyle.BreakBeforeBinaryOperators = FormatStyle::BOS_NonAssignment; GoogleStyle.MaxEmptyLinesToKeep = 3; GoogleStyle.SpacesInContainerLiterals = false; GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline; diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 83b74216fb2..c91d378dd4a 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -8709,7 +8709,7 @@ TEST_F(FormatTest, UsesLanguageForBasedOnStyle) { Style.Language = FormatStyle::LK_JavaScript; Style.BreakBeforeTernaryOperators = true; EXPECT_EQ(0, parseConfiguration("BasedOnStyle: Google", &Style).value()); - EXPECT_FALSE(Style.BreakBeforeTernaryOperators); + EXPECT_FALSE(Style.SpacesInContainerLiterals); Style.BreakBeforeTernaryOperators = true; EXPECT_EQ(0, parseConfiguration("---\n" @@ -8718,7 +8718,7 @@ TEST_F(FormatTest, UsesLanguageForBasedOnStyle) { "Language: JavaScript\n" "IndentWidth: 76\n" "...\n", &Style).value()); - EXPECT_FALSE(Style.BreakBeforeTernaryOperators); + EXPECT_FALSE(Style.SpacesInContainerLiterals); EXPECT_EQ(76u, Style.IndentWidth); EXPECT_EQ(FormatStyle::LK_JavaScript, Style.Language); } diff --git a/clang/unittests/Format/FormatTestJS.cpp b/clang/unittests/Format/FormatTestJS.cpp index 6ee150c6624..30d7c37818c 100644 --- a/clang/unittests/Format/FormatTestJS.cpp +++ b/clang/unittests/Format/FormatTestJS.cpp @@ -55,29 +55,27 @@ TEST_F(FormatTestJS, UnderstandsJavaScriptOperators) { verifyFormat("a != = b;"); verifyFormat("a === b;"); - verifyFormat("aaaaaaa ===\n b;", getGoogleJSStyleWithColumns(10)); + verifyFormat("aaaaaaa\n === b;", getGoogleJSStyleWithColumns(10)); verifyFormat("a !== b;"); - verifyFormat("aaaaaaa !==\n b;", getGoogleJSStyleWithColumns(10)); - verifyFormat("if (a + b + c +\n" - " d !==\n" - " e + f + g)\n" + verifyFormat("aaaaaaa\n !== b;", getGoogleJSStyleWithColumns(10)); + verifyFormat("if (a + b + c + d\n" + " !== e + f + g)\n" " q();", getGoogleJSStyleWithColumns(20)); verifyFormat("a >> >= b;"); verifyFormat("a >>> b;"); - verifyFormat("aaaaaaa >>>\n b;", getGoogleJSStyleWithColumns(10)); + verifyFormat("aaaaaaa\n >>> b;", getGoogleJSStyleWithColumns(10)); verifyFormat("a >>>= b;"); - verifyFormat("aaaaaaa >>>=\n b;", getGoogleJSStyleWithColumns(10)); - verifyFormat("if (a + b + c +\n" - " d >>>\n" - " e + f + g)\n" + verifyFormat("aaaaaaa\n >>>= b;", getGoogleJSStyleWithColumns(10)); + verifyFormat("if (a + b + c + d\n" + " >>> e + f + g)\n" " q();", getGoogleJSStyleWithColumns(20)); - verifyFormat("var x = aaaaaaaaaa ?\n" - " bbbbbb :\n" - " ccc;", + verifyFormat("var x = aaaaaaaaaa\n" + " ? bbbbbb\n" + " : ccc;", getGoogleJSStyleWithColumns(20)); verifyFormat("var b = a.map((x) => x + 1);"); @@ -183,11 +181,10 @@ TEST_F(FormatTestJS, FunctionLiterals) { " }\n" "};"); // FIXME: The formatting here probably isn't ideal. - EXPECT_EQ("abc = xyz ?\n" - " function() {\n" - " return 1;\n" - " } :\n" - " function() {\n" + EXPECT_EQ("abc = xyz ? function() {\n" + " return 1;\n" + " }\n" + " : function() {\n" " return -1;\n" "};", format("abc=xyz?function(){return 1;}:function(){return -1;};")); |