]> granicus.if.org Git - clang/commitdiff
clang-format: [JS] Indent namespaces in JavaScript/TS by default.
authorMartin Probst <martin@probst.io>
Mon, 13 Jun 2016 16:41:28 +0000 (16:41 +0000)
committerMartin Probst <martin@probst.io>
Mon, 13 Jun 2016 16:41:28 +0000 (16:41 +0000)
Summary: There's no convention of avoiding the nested indentation.

Reviewers: djasper

Subscribers: klimek, alexeagle, cfe-commits

Differential Revision: http://reviews.llvm.org/D21275

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@272559 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Format/Format.cpp
unittests/Format/FormatTestJS.cpp

index fc93d18ce12643442a40a5c629283f9e788a23fd..c73ef5061bf4d89e8631797da015ae072004a0ee 100644 (file)
@@ -612,6 +612,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) {
     GoogleStyle.BreakBeforeTernaryOperators = false;
     GoogleStyle.CommentPragmas = "@(export|return|see|visibility) ";
     GoogleStyle.MaxEmptyLinesToKeep = 3;
+    GoogleStyle.NamespaceIndentation = FormatStyle::NI_All;
     GoogleStyle.SpacesInContainerLiterals = false;
     GoogleStyle.JavaScriptQuotes = FormatStyle::JSQS_Single;
     GoogleStyle.JavaScriptWrapImports = false;
index 36c3dd08cbae4bf2dce6e21539bbb3590aa7a8b7..75b53a578798b61f562b0fc9e963592e555a3e75 100644 (file)
@@ -315,6 +315,15 @@ TEST_F(FormatTestJS, GoogModules) {
       "    goog.module.get('my.long.module.name.followedBy.MyLongClassName');");
 }
 
+TEST_F(FormatTestJS, FormatsNamespaces) {
+  verifyFormat("namespace Foo {\n"
+               "  export let x = 1;\n"
+               "}\n");
+  verifyFormat("declare namespace Foo {\n"
+               "  export let x: number;\n"
+               "}\n");
+}
+
 TEST_F(FormatTestJS, FormatsFreestandingFunctions) {
   verifyFormat("function outer1(a, b) {\n"
                "  function inner1(a, b) { return a; }\n"