https://github.com/HerrCai0907 updated https://github.com/llvm/llvm-project/pull/96122
>From 41993ea6903668c41eef8a4477f5914c894f7109 Mon Sep 17 00:00:00 2001 From: Congcong Cai <congcongcai0...@163.com> Date: Wed, 19 Jun 2024 23:20:09 +0000 Subject: [PATCH 1/2] [clang-tidy] add option to avoid "no checks enabled" error When clang-tidy get an empty checks, it will throw "no checks enabled" error and exit with non-zero return value. It make clang-tidy's wrapper program confused when in big project some files don't want to be checked and use `-checks=-*` to disable all checks. --- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp | 12 ++++++++++-- clang-tools-extra/docs/ReleaseNotes.rst | 3 +++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index 7388f20ef288e..b579aff4394c9 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -325,6 +325,14 @@ option is recognized. )"), cl::init(false), cl::cat(ClangTidyCategory)); +static cl::opt<bool> AllowEmptyCheckList("allow-empty-checks", desc(R"( +Allow empty enabled checks. This suppresses +the "no checks enabled" error when disabling +all of the checks. +)"), + cl::init(false), + cl::cat(ClangTidyCategory)); + namespace clang::tidy { static void printStats(const ClangTidyStats &Stats) { @@ -598,7 +606,7 @@ int clangTidyMain(int argc, const char **argv) { } if (ListChecks) { - if (EnabledChecks.empty()) { + if (EnabledChecks.empty() && !AllowEmptyCheckList) { llvm::errs() << "No checks enabled.\n"; return 1; } @@ -651,7 +659,7 @@ int clangTidyMain(int argc, const char **argv) { return 0; } - if (EnabledChecks.empty()) { + if (EnabledChecks.empty() && !AllowEmptyCheckList) { llvm::errs() << "Error: no checks enabled.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 3bdd735f7dcf7..54cfcafd121b6 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -125,6 +125,9 @@ Improvements to clang-tidy - Added argument `--exclude-header-filter` and config option `ExcludeHeaderFilterRegex` to exclude headers from analysis via a RegEx. +- Added argument `--allow-empty-checks` and config option `AllowEmptyCheckList` + to suppress "no checks enabled" error when disabling all of the checks. + New checks ^^^^^^^^^^ >From 9302feee8fa9d19711ad2126dddbd73c044502b0 Mon Sep 17 00:00:00 2001 From: Congcong Cai <congcongcai0...@163.com> Date: Thu, 20 Jun 2024 17:58:10 +0800 Subject: [PATCH 2/2] fix acc comment --- clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp | 6 +++--- clang-tools-extra/docs/ReleaseNotes.rst | 4 ++-- clang-tools-extra/docs/clang-tidy/index.rst | 3 +++ 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp index b579aff4394c9..1475816827ac4 100644 --- a/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp +++ b/clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp @@ -325,7 +325,7 @@ option is recognized. )"), cl::init(false), cl::cat(ClangTidyCategory)); -static cl::opt<bool> AllowEmptyCheckList("allow-empty-checks", desc(R"( +static cl::opt<bool> AllowNoChecks("allow-no-checks", desc(R"( Allow empty enabled checks. This suppresses the "no checks enabled" error when disabling all of the checks. @@ -606,7 +606,7 @@ int clangTidyMain(int argc, const char **argv) { } if (ListChecks) { - if (EnabledChecks.empty() && !AllowEmptyCheckList) { + if (EnabledChecks.empty() && !AllowNoChecks) { llvm::errs() << "No checks enabled.\n"; return 1; } @@ -659,7 +659,7 @@ int clangTidyMain(int argc, const char **argv) { return 0; } - if (EnabledChecks.empty() && !AllowEmptyCheckList) { + if (EnabledChecks.empty() && !AllowNoChecks) { llvm::errs() << "Error: no checks enabled.\n"; llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); return 1; diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 54cfcafd121b6..e9a9cd47e9215 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -125,8 +125,8 @@ Improvements to clang-tidy - Added argument `--exclude-header-filter` and config option `ExcludeHeaderFilterRegex` to exclude headers from analysis via a RegEx. -- Added argument `--allow-empty-checks` and config option `AllowEmptyCheckList` - to suppress "no checks enabled" error when disabling all of the checks. +- Added argument `--allow-no-checks` to suppress "no checks enabled" error + when disabling all of the checks. New checks ^^^^^^^^^^ diff --git a/clang-tools-extra/docs/clang-tidy/index.rst b/clang-tools-extra/docs/clang-tidy/index.rst index 9ccacefa3c2c5..c8fc34c61caeb 100644 --- a/clang-tools-extra/docs/clang-tidy/index.rst +++ b/clang-tools-extra/docs/clang-tidy/index.rst @@ -240,6 +240,9 @@ An overview of all the command-line options: This option's value is appended to the value of the 'WarningsAsErrors' option in .clang-tidy file, if any. + --allow-no-checks - Allow empty enabled checks. This suppresses + the "no checks enabled" error when disabling + all of the checks. -p <build-path> is used to read a compile command database. _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits