From: Martin Probst Date: Mon, 13 Jun 2016 16:41:28 +0000 (+0000) Subject: clang-format: [JS] Indent namespaces in JavaScript/TS by default. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=aa6f4a7a3e3bbc248f86859a8d7f5af4bebef16b;p=clang clang-format: [JS] Indent namespaces in JavaScript/TS by default. 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 --- diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index fc93d18ce1..c73ef5061b 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -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; diff --git a/unittests/Format/FormatTestJS.cpp b/unittests/Format/FormatTestJS.cpp index 36c3dd08cb..75b53a5787 100644 --- a/unittests/Format/FormatTestJS.cpp +++ b/unittests/Format/FormatTestJS.cpp @@ -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"