r280878 - clang-format: [JavaScript] Change default AllowShortFunctionsOnASingleLine
Daniel Jasper via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 7 16:01:13 PDT 2016
Author: djasper
Date: Wed Sep 7 18:01:13 2016
New Revision: 280878
URL: http://llvm.org/viewvc/llvm-project?rev=280878&view=rev
Log:
clang-format: [JavaScript] Change default AllowShortFunctionsOnASingleLine
for Google style to "empty".
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=280878&r1=280877&r2=280878&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Sep 7 18:01:13 2016
@@ -610,7 +610,7 @@ FormatStyle getGoogleStyle(FormatStyle::
} else if (Language == FormatStyle::LK_JavaScript) {
GoogleStyle.AlignAfterOpenBracket = FormatStyle::BAS_AlwaysBreak;
GoogleStyle.AlignOperands = false;
- GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
+ GoogleStyle.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Empty;
GoogleStyle.AlwaysBreakBeforeMultilineStrings = false;
GoogleStyle.BreakBeforeTernaryOperators = false;
GoogleStyle.CommentPragmas = "@(export|requirecss|return|see|visibility) ";
Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=280878&r1=280877&r2=280878&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Sep 7 18:01:13 2016
@@ -161,7 +161,11 @@ TEST_F(FormatTestJS, ES6DestructuringAss
}
TEST_F(FormatTestJS, ContainerLiterals) {
- verifyFormat("var x = {y: function(a) { return a; }};");
+ verifyFormat("var x = {\n"
+ " y: function(a) {\n"
+ " return a;\n"
+ " }\n"
+ "};");
verifyFormat("return {\n"
" link: function() {\n"
" f(); //\n"
@@ -212,7 +216,11 @@ TEST_F(FormatTestJS, ContainerLiterals)
verifyFormat("x = foo && {a: 123};");
// Arrow functions in object literals.
- verifyFormat("var x = {y: (a) => { return a; }};");
+ verifyFormat("var x = {\n"
+ " y: (a) => {\n"
+ " return a;\n"
+ " }\n"
+ "};");
verifyFormat("var x = {y: (a) => a};");
// Computed keys.
@@ -326,11 +334,15 @@ TEST_F(FormatTestJS, FormatsNamespaces)
TEST_F(FormatTestJS, FormatsFreestandingFunctions) {
verifyFormat("function outer1(a, b) {\n"
- " function inner1(a, b) { return a; }\n"
+ " function inner1(a, b) {\n"
+ " return a;\n"
+ " }\n"
" inner1(a, b);\n"
"}\n"
"function outer2(a, b) {\n"
- " function inner2(a, b) { return a; }\n"
+ " function inner2(a, b) {\n"
+ " return a;\n"
+ " }\n"
" inner2(a, b);\n"
"}");
verifyFormat("function f() {}");
@@ -350,7 +362,9 @@ TEST_F(FormatTestJS, GeneratorFunctions)
" yield 1;\n"
"}\n");
verifyFormat("class X {\n"
- " * generatorMethod() { yield x; }\n"
+ " * generatorMethod() {\n"
+ " yield x;\n"
+ " }\n"
"}");
}
@@ -366,7 +380,9 @@ TEST_F(FormatTestJS, AsyncFunctions) {
" return fetch(x);\n"
"}");
verifyFormat("class X {\n"
- " async asyncMethod() { return fetch(1); }\n"
+ " async asyncMethod() {\n"
+ " return fetch(1);\n"
+ " }\n"
"}");
verifyFormat("function initialize() {\n"
" // Comment.\n"
@@ -423,8 +439,10 @@ TEST_F(FormatTestJS, ColumnLayoutForArra
}
TEST_F(FormatTestJS, FunctionLiterals) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+ Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_Inline;
verifyFormat("doFoo(function() {});");
- verifyFormat("doFoo(function() { return 1; });");
+ verifyFormat("doFoo(function() { return 1; });", Style);
verifyFormat("var func = function() {\n"
" return 1;\n"
"};");
@@ -438,7 +456,8 @@ TEST_F(FormatTestJS, FunctionLiterals) {
" getAttribute: function(key) { return this[key]; },\n"
" style: {direction: ''}\n"
" }\n"
- "};");
+ "};",
+ Style);
verifyFormat("abc = xyz ? function() {\n"
" return 1;\n"
"} : function() {\n"
@@ -476,13 +495,6 @@ TEST_F(FormatTestJS, FunctionLiterals) {
" // code\n"
" });");
- verifyFormat("f({a: function() { return 1; }});",
- getGoogleJSStyleWithColumns(33));
- verifyFormat("f({\n"
- " a: function() { return 1; }\n"
- "});",
- getGoogleJSStyleWithColumns(32));
-
verifyFormat("return {\n"
" a: function SomeFunction() {\n"
" // ...\n"
@@ -510,6 +522,15 @@ TEST_F(FormatTestJS, FunctionLiterals) {
" .doSomethingElse(\n"
" // break\n"
" );");
+
+ Style.ColumnLimit = 33;
+ verifyFormat("f({a: function() { return 1; }});", Style);
+ Style.ColumnLimit = 32;
+ verifyFormat("f({\n"
+ " a: function() { return 1; }\n"
+ "});",
+ Style);
+
}
TEST_F(FormatTestJS, InliningFunctionLiterals) {
@@ -570,6 +591,8 @@ TEST_F(FormatTestJS, InliningFunctionLit
}
TEST_F(FormatTestJS, MultipleFunctionLiterals) {
+ FormatStyle Style = getGoogleStyle(FormatStyle::LK_JavaScript);
+ Style.AllowShortFunctionsOnASingleLine = FormatStyle::SFS_All;
verifyFormat("promise.then(\n"
" function success() {\n"
" doFoo();\n"
@@ -606,7 +629,8 @@ TEST_F(FormatTestJS, MultipleFunctionLit
" .thenCatch(function(error) {\n"
" body();\n"
" body();\n"
- " });");
+ " });",
+ Style);
verifyFormat("getSomeLongPromise()\n"
" .then(function(value) {\n"
" body();\n"
@@ -619,7 +643,8 @@ TEST_F(FormatTestJS, MultipleFunctionLit
verifyFormat("getSomeLongPromise()\n"
" .then(function(value) { body(); })\n"
- " .thenCatch(function(error) { body(); });");
+ " .thenCatch(function(error) { body(); });",
+ Style);
verifyFormat("return [aaaaaaaaaaaaaaaaaaaaaa]\n"
" .aaaaaaa(function() {\n"
@@ -633,7 +658,9 @@ TEST_F(FormatTestJS, ArrowFunctions) {
" return a;\n"
"};");
verifyFormat("var x = (a) => {\n"
- " function y() { return 42; }\n"
+ " function y() {\n"
+ " return 42;\n"
+ " }\n"
" return a;\n"
"};");
verifyFormat("var x = (a: type): {some: type} => {\n"
@@ -901,8 +928,16 @@ TEST_F(FormatTestJS, TypeAnnotations) {
verifyFormat("((a: string, b: number): string => a + b);");
verifyFormat("var x: (y: number) => string;");
verifyFormat("var x: P<string, (a: number) => string>;");
- verifyFormat("var x = {y: function(): z { return 1; }};");
- verifyFormat("var x = {y: function(): {a: number} { return 1; }};");
+ verifyFormat("var x = {\n"
+ " y: function(): z {\n"
+ " return 1;\n"
+ " }\n"
+ "};");
+ verifyFormat("var x = {\n"
+ " y: function(): {a: number} {\n"
+ " return 1;\n"
+ " }\n"
+ "};");
verifyFormat("function someFunc(args: string[]):\n"
" {longReturnValue: string[]} {}",
getGoogleJSStyleWithColumns(60));
@@ -930,7 +965,7 @@ TEST_F(FormatTestJS, ClassDeclarations)
verifyFormat("class C {\n ['x' + 2]: string = 12;\n}");
verifyFormat("class C {\n private x: string = 12;\n}");
verifyFormat("class C {\n private static x: string = 12;\n}");
- verifyFormat("class C {\n static x(): string { return 'asd'; }\n}");
+ verifyFormat("class C {\n static x(): string {\n return 'asd';\n }\n}");
verifyFormat("class C extends P implements I {}");
verifyFormat("class C extends p.P implements i.I {}");
verifyFormat("class Test {\n"
@@ -1093,7 +1128,9 @@ TEST_F(FormatTestJS, Modules) {
verifyFormat("export default () => {};");
verifyFormat("export interface Foo { foo: number; }\n"
"export class Bar {\n"
- " blah(): string { return this.blah; };\n"
+ " blah(): string {\n"
+ " return this.blah;\n"
+ " };\n"
"}");
}
More information about the cfe-commits
mailing list