[clang-tools-extra] 164ed7b - [clangd] Enable some nice clang-tidy checks by default.
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Fri Apr 3 06:40:17 PDT 2020
Author: Sam McCall
Date: 2020-04-03T15:40:07+02:00
New Revision: 164ed7b1d0446400123189c9cd168df5448e4233
URL: https://github.com/llvm/llvm-project/commit/164ed7b1d0446400123189c9cd168df5448e4233
DIFF: https://github.com/llvm/llvm-project/commit/164ed7b1d0446400123189c9cd168df5448e4233.diff
LOG: [clangd] Enable some nice clang-tidy checks by default.
Reviewers: hokein
Subscribers: ilya-biryukov, MaskRay, jkorous, arphaman, kadircet, usaxena95, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D77348
Added:
Modified:
clang-tools-extra/clangd/tool/ClangdMain.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp
index 9bfc58b55f71..4b3b565ac2b6 100644
--- a/clang-tools-extra/clangd/tool/ClangdMain.cpp
+++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp
@@ -691,18 +691,42 @@ clangd accepts flags on the commandline, and in the CLANGD_FLAGS environment var
std::unique_ptr<tidy::ClangTidyOptionsProvider>
ClangTidyOptProvider; /*GUARDED_BY(ClangTidyOptMu)*/
if (EnableClangTidy) {
- auto OverrideClangTidyOptions = tidy::ClangTidyOptions::getDefaults();
- OverrideClangTidyOptions.Checks = ClangTidyChecks;
+ auto EmptyDefaults = tidy::ClangTidyOptions::getDefaults();
+ EmptyDefaults.Checks.reset(); // So we can tell if checks were ever set.
+ tidy::ClangTidyOptions OverrideClangTidyOptions;
+ if (!ClangTidyChecks.empty())
+ OverrideClangTidyOptions.Checks = ClangTidyChecks;
ClangTidyOptProvider = std::make_unique<tidy::FileOptionsProvider>(
tidy::ClangTidyGlobalOptions(),
- /* Default */ tidy::ClangTidyOptions::getDefaults(),
+ /* Default */ EmptyDefaults,
/* Override */ OverrideClangTidyOptions, FSProvider.getFileSystem());
Opts.GetClangTidyOptions = [&](llvm::vfs::FileSystem &,
llvm::StringRef File) {
// This function must be thread-safe and tidy option providers are not.
- std::lock_guard<std::mutex> Lock(ClangTidyOptMu);
- // FIXME: use the FS provided to the function.
- return ClangTidyOptProvider->getOptions(File);
+ tidy::ClangTidyOptions Opts;
+ {
+ std::lock_guard<std::mutex> Lock(ClangTidyOptMu);
+ // FIXME: use the FS provided to the function.
+ Opts = ClangTidyOptProvider->getOptions(File);
+ }
+ if (!Opts.Checks) {
+ // If the user hasn't configured clang-tidy checks at all, including
+ // via .clang-tidy, give them a nice set of checks.
+ // (This should be what the "default" options does, but it isn't...)
+ //
+ // These default checks are chosen for:
+ // - low false-positive rate
+ // - providing a lot of value
+ // - being reasonably efficient
+ Opts.Checks = llvm::join_items(
+ ",", "readability-misleading-indentation",
+ "readability-deleted-default", "bugprone-integer-division",
+ "bugprone-sizeof-expression", "bugprone-suspicious-missing-comma",
+ "bugprone-unused-raii", "bugprone-unused-return-value",
+ "misc-unused-using-decls", "misc-unused-alias-decls",
+ "misc-definitions-in-headers");
+ }
+ return Opts;
};
}
Opts.SuggestMissingIncludes = SuggestMissingIncludes;
More information about the cfe-commits
mailing list