[clang-tidy] Make format style customizable
Summary: I came across an outstanding FIXME to make the format style customizable. Inspired by the include fixer, I added an new option `-style` to configure the fallback style in case no clang-format configuration file is found. The default remains "llvm".
Reviewers: Prazek, aaron.ballman, hokein, alexfh
Subscribers: cfe-commits, malcolm.parsons
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D27142
llvm-svn: 288258
diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
index 8578ef4..fd53c4e 100644
--- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
+++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
@@ -49,9 +49,9 @@
)");
-const char DefaultChecks[] = // Enable these checks by default:
- "clang-diagnostic-*," // * compiler diagnostics
- "clang-analyzer-*"; // * Static Analyzer checks
+const char DefaultChecks[] = // Enable these checks by default:
+ "clang-diagnostic-*," // * compiler diagnostics
+ "clang-analyzer-*"; // * Static Analyzer checks
static cl::opt<std::string> Checks("checks", cl::desc(R"(
Comma-separated list of globs with optional '-'
@@ -120,6 +120,13 @@
)"),
cl::init(false), cl::cat(ClangTidyCategory));
+static cl::opt<std::string> FormatStyle("style", cl::desc(R"(
+Fallback style for reformatting after inserting fixes
+if there is no clang-format config file found.
+)"),
+ cl::init("llvm"),
+ cl::cat(ClangTidyCategory));
+
static cl::opt<bool> ListChecks("list-checks", cl::desc(R"(
List all enabled checks and exit. Use with
-checks=* to list all available checks.
@@ -386,7 +393,8 @@
unsigned WErrorCount = 0;
// -fix-errors implies -fix.
- handleErrors(Errors, (FixErrors || Fix) && !DisableFixes, WErrorCount);
+ handleErrors(Errors, (FixErrors || Fix) && !DisableFixes, FormatStyle,
+ WErrorCount);
if (!ExportFixes.empty() && !Errors.empty()) {
std::error_code EC;