diff --git a/clang-tools-extra/clangd/tool/ClangdMain.cpp b/clang-tools-extra/clangd/tool/ClangdMain.cpp --- a/clang-tools-extra/clangd/tool/ClangdMain.cpp +++ b/clang-tools-extra/clangd/tool/ClangdMain.cpp @@ -691,18 +691,42 @@ std::unique_ptr 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::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 Lock(ClangTidyOptMu); - // FIXME: use the FS provided to the function. - return ClangTidyOptProvider->getOptions(File); + tidy::ClangTidyOptions Opts; + { + std::lock_guard 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;