diff --git a/src/Clazy.cpp b/src/Clazy.cpp --- a/src/Clazy.cpp +++ b/src/Clazy.cpp @@ -271,7 +271,8 @@ { std::lock_guard lock(CheckManager::lock()); - m_checks = m_checkManager->requestedChecks(m_context, args); + m_checks = m_checkManager->requestedChecks(args, + m_options & ClazyContext::ClazyOption_Qt4Compat); } if (args.size() > 1) { @@ -390,7 +391,8 @@ auto cm = CheckManager::instance(); vector checks; checks.push_back(m_checkList); - const RegisteredCheck::List requestedChecks = cm->requestedChecks(context, checks); + const bool qt4Compat = m_options & ClazyContext::ClazyOption_Qt4Compat; + const RegisteredCheck::List requestedChecks = cm->requestedChecks(checks, qt4Compat); if (requestedChecks.size() == 0) { llvm::errs() << "No checks were requested!\n" << "\n"; diff --git a/src/ClazyStandaloneMain.cpp b/src/ClazyStandaloneMain.cpp --- a/src/ClazyStandaloneMain.cpp +++ b/src/ClazyStandaloneMain.cpp @@ -78,6 +78,9 @@ static cl::opt s_supportedChecks("supported-checks-json", cl::desc("Dump meta information about supported checks in JSON format."), cl::init(false), cl::cat(s_clazyCategory)); +static cl::opt s_listEnabledChecks("list-checks", cl::desc("List all enabled checks and exit."), + cl::init(false), cl::cat(s_clazyCategory)); + static cl::extrahelp s_commonHelp(CommonOptionsParser::HelpMessage); class ClazyToolActionFactory @@ -129,6 +132,23 @@ return 0; } + if (s_listEnabledChecks.getValue()) { + std::string checksFromArgs = s_checks.getValue(); + std::vector checks = { checksFromArgs.empty() ? "level1" : checksFromArgs }; + const RegisteredCheck::List enabledChecks + = CheckManager::instance()->requestedChecks(checks, s_qt4Compat.getValue()); + + if (!enabledChecks.empty()) { + llvm::outs() << "Enabled checks:"; + for (const auto &check : enabledChecks) { + llvm::outs() << "\n " << check.name; + } + llvm::outs() << "\n"; + } + + return 0; + } + ClangTool tool(optionsParser.getCompilations(), optionsParser.getSourcePathList()); return tool.run(new ClazyToolActionFactory(optionsParser.getSourcePathList())); diff --git a/src/checkmanager.h b/src/checkmanager.h --- a/src/checkmanager.h +++ b/src/checkmanager.h @@ -105,7 +105,7 @@ * Returns all the requested checks. * This is a union of the requested checks via env variable and via arguments passed to compiler */ - RegisteredCheck::List requestedChecks(const ClazyContext *context, std::vector &args); + RegisteredCheck::List requestedChecks(std::vector &args, bool qt4Compat); std::vector> createChecks(const RegisteredCheck::List &requestedChecks, ClazyContext *context); static void removeChecksFromList(RegisteredCheck::List &list, std::vector &checkNames); diff --git a/src/checkmanager.cpp b/src/checkmanager.cpp --- a/src/checkmanager.cpp +++ b/src/checkmanager.cpp @@ -171,7 +171,7 @@ return false; } -RegisteredCheck::List CheckManager::requestedChecks(const ClazyContext *context, std::vector &args) +RegisteredCheck::List CheckManager::requestedChecks(std::vector &args, bool qt4Compat) { RegisteredCheck::List result; @@ -213,7 +213,7 @@ clazy::sort_and_remove_dups(result, checkLessThan); CheckManager::removeChecksFromList(result, userDisabledChecks); - if (context->options & ClazyContext::ClazyOption_Qt4Compat) { + if (qt4Compat) { // #5 Remove Qt4 incompatible checks result.erase(remove_if(result.begin(), result.end(), [](const RegisteredCheck &c){ return c.options & RegisteredCheck::Option_Qt4Incompatible;