Skip to content
14 changes: 13 additions & 1 deletion clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,14 @@ option is recognized.
)"),
cl::init(false), cl::cat(ClangTidyCategory));

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.
)"),
cl::init(false),
cl::cat(ClangTidyCategory));

namespace clang::tidy {

static void printStats(const ClangTidyStats &Stats) {
Expand Down Expand Up @@ -598,7 +606,7 @@ int clangTidyMain(int argc, const char **argv) {
}

if (ListChecks) {
if (EnabledChecks.empty()) {
if (EnabledChecks.empty() && !AllowNoChecks) {
llvm::errs() << "No checks enabled.\n";
return 1;
}
Expand Down Expand Up @@ -652,6 +660,10 @@ int clangTidyMain(int argc, const char **argv) {
}

if (EnabledChecks.empty()) {
if (AllowNoChecks) {
llvm::outs() << "No checks enabled.\n";
return 0;
}
llvm::errs() << "Error: no checks enabled.\n";
llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
return 1;
Expand Down
7 changes: 7 additions & 0 deletions clang-tools-extra/clang-tidy/tool/clang-tidy-diff.py
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ def main():
default=[],
help="Load the specified plugin in clang-tidy.",
)
parser.add_argument(
"-allow-no-checks",
action="store_true",
help="Allow empty enabled checks.",
)

clang_tidy_args = []
argv = sys.argv[1:]
Expand Down Expand Up @@ -327,6 +332,8 @@ def main():
common_clang_tidy_args.append("-p=%s" % args.build_path)
if args.use_color:
common_clang_tidy_args.append("--use-color")
if args.allow_no_checks:
common_clang_tidy_args.append("--allow-no-checks")
for arg in args.extra_arg:
common_clang_tidy_args.append("-extra-arg=%s" % arg)
for arg in args.extra_arg_before:
Expand Down
10 changes: 10 additions & 0 deletions clang-tools-extra/clang-tidy/tool/run-clang-tidy.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ def get_tidy_invocation(
plugins,
warnings_as_errors,
exclude_header_filter,
allow_no_checks,
):
"""Gets a command line for clang-tidy."""
start = [clang_tidy_binary]
Expand Down Expand Up @@ -147,6 +148,8 @@ def get_tidy_invocation(
start.append("-load=" + plugin)
if warnings_as_errors:
start.append("--warnings-as-errors=" + warnings_as_errors)
if allow_no_checks:
start.append("--allow-no-checks")
start.append(f)
return start

Expand Down Expand Up @@ -232,6 +235,7 @@ def run_tidy(args, clang_tidy_binary, tmpdir, build_path, queue, lock, failed_fi
args.plugins,
args.warnings_as_errors,
args.exclude_header_filter,
args.allow_no_checks,
)

proc = subprocess.Popen(
Expand Down Expand Up @@ -402,6 +406,11 @@ def main():
default=None,
help="Upgrades warnings to errors. Same format as '-checks'",
)
parser.add_argument(
"-allow-no-checks",
action="store_true",
help="Allow empty enabled checks.",
)
args = parser.parse_args()

db_path = "compile_commands.json"
Expand Down Expand Up @@ -463,6 +472,7 @@ def main():
args.plugins,
args.warnings_as_errors,
args.exclude_header_filter,
args.allow_no_checks,
)
invocation.append("-list-checks")
invocation.append("-")
Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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-no-checks` to suppress "no checks enabled" error
when disabling all of the checks by `--checks='-*'`.

New checks
^^^^^^^^^^

Expand Down
3 changes: 3 additions & 0 deletions clang-tools-extra/docs/clang-tidy/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// RUN: not clang-tidy %s -checks='-*'
// RUN: clang-tidy %s -checks='-*' --allow-no-checks | FileCheck --match-full-lines %s

// CHECK: No checks enabled.