summaryrefslogtreecommitdiffstats
path: root/unittests
diff options
context:
space:
mode:
authorMartin Probst <martin@probst.io>2017-05-09 20:04:09 +0000
committerMartin Probst <martin@probst.io>2017-05-09 20:04:09 +0000
commitcf44d2c1ae91204501745bb512206974a4c29ba0 (patch)
treef408e0ff5719e8307b57b4c6a29aff0203f3e672 /unittests
parentb6c02e8e5ac5de00590d22161a0eac44cb9a4a8a (diff)
clang-format: [JS] Don't indent JavaScript IIFEs.
Because IIFEs[1] are often used like an anonymous namespace around large sections of JavaScript code, it's useful not to indent to them (which effectively reduces the column limit by the indent amount needlessly). It's also common for developers to wrap these around entire files or libraries. When adopting clang-format, changing the indent entire file can reduce the usefulness of the blame annotations. Patch by danbeam, thanks! Differential Revision: https://reviews.llvm.org/D32989 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@302580 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r--unittests/Format/FormatTestJS.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp
index 288975374d..05aee91a1d 100644
--- a/unittests/Format/FormatTestJS.cpp
+++ b/unittests/Format/FormatTestJS.cpp
@@ -367,6 +367,25 @@ TEST_F(FormatTestJS, GoogScopes) {
"});");
}
+TEST_F(FormatTestJS, IIFEs) {
+ // Internal calling parens; no semi.
+ verifyFormat("(function() {\n"
+ "var a = 1;\n"
+ "}())");
+ // External calling parens; no semi.
+ verifyFormat("(function() {\n"
+ "var b = 2;\n"
+ "})()");
+ // Internal calling parens; with semi.
+ verifyFormat("(function() {\n"
+ "var c = 3;\n"
+ "}());");
+ // External calling parens; with semi.
+ verifyFormat("(function() {\n"
+ "var d = 4;\n"
+ "})();");
+}
+
TEST_F(FormatTestJS, GoogModules) {
verifyFormat("goog.module('this.is.really.absurdly.long');",
getGoogleJSStyleWithColumns(40));