From 358a36e5760dd3c6d235099a29b7be6203c7fe99 Mon Sep 17 00:00:00 2001 From: Jordan Rupprecht Date: Fri, 1 Mar 2019 00:12:18 +0000 Subject: [PATCH] [clang-format][TableGen] Don't add spaces around items in square braces. Summary: clang-formatting wants to add spaces around items in square braces, e.g. [1, 2] -> [ 1, 2 ]. Based on a quick check [1], it seems like most cases are using the [1, 2] format, so make that the consistent one. [1] in llvm `.td` files, the regex `\[[^ ]` (bracket followed by not-a-space) shows up ~400 times, but `\[\s[^ ]` (bracket followed by one space and one not-a-space) shows up ~40 times => ~90% uses this format. Reviewers: djasper, krasimir, MyDeveloperDay Reviewed By: MyDeveloperDay Subscribers: MyDeveloperDay, arphaman, cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D55964 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@355158 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Format/Format.cpp | 5 +++++ unittests/Format/FormatTestTableGen.cpp | 4 ++++ 2 files changed, 9 insertions(+) diff --git a/lib/Format/Format.cpp b/lib/Format/Format.cpp index d8751a36d7..1827c4a8b1 100644 --- a/lib/Format/Format.cpp +++ b/lib/Format/Format.cpp @@ -718,6 +718,11 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) { LLVMStyle.StatementMacros.push_back("Q_UNUSED"); LLVMStyle.StatementMacros.push_back("QT_REQUIRE_VERSION"); + // Defaults that differ when not C++. + if (Language == FormatStyle::LK_TableGen) { + LLVMStyle.SpacesInContainerLiterals = false; + } + return LLVMStyle; } diff --git a/unittests/Format/FormatTestTableGen.cpp b/unittests/Format/FormatTestTableGen.cpp index b3771f6d81..06029bd8c7 100644 --- a/unittests/Format/FormatTestTableGen.cpp +++ b/unittests/Format/FormatTestTableGen.cpp @@ -51,5 +51,9 @@ TEST_F(FormatTestTableGen, FormatStringBreak) { " \"very long help string\">;\n"); } +TEST_F(FormatTestTableGen, NoSpacesInSquareBracketLists) { + verifyFormat("def flag : Flag<[\"-\", \"--\"], \"foo\">;\n"); +} + } // namespace format } // end namespace clang -- 2.40.0