Add a clang-tidy plugin containing one check to replace implicit conversions (as enabled by default with JSON_USE_IMPLICIT_CONVERSIONS) with explicit ones. This will make it easier for library users to switch away from using implicit conversions which should make it possible for the library to start disallowing them sooner. Being able to test the plugin in a similar way to how checks are tested within clang-tidy itself requires copying the check_clang_tidy.py script from the LLVM code itself. The check itself is virtually identical to the one proposed for inclusion in clang-tidy itself at https://github.com/llvm/llvm-project/pull/126425 . Unfortunately it is necessary to add "C" to the languages for the project in CMakeLists.txt for find_package to work for LLVM. Signed-off-by: Mike Crowe <mac@mcrowe.com>
32 lines
923 B
C++
32 lines
923 B
C++
// SPDX-FileCopyrightText: 2025 Mike Crowe
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
#include "clang-tidy/ClangTidyModule.h"
|
|
#include "clang-tidy/ClangTidyModuleRegistry.h"
|
|
#include "ModernizeNlohmannJsonExplicitConversionsCheck.h"
|
|
|
|
namespace {
|
|
|
|
using namespace clang::tidy;
|
|
|
|
class NlohmannJsonChecksModule : public ClangTidyModule
|
|
{
|
|
public:
|
|
void addCheckFactories(ClangTidyCheckFactories& CheckFactories) override
|
|
{
|
|
CheckFactories.registerCheck<clang::tidy::modernize::NlohmannJsonExplicitConversionsCheck>(
|
|
"modernize-nlohmann-json-explicit-conversions");
|
|
}
|
|
};
|
|
|
|
} // namespace
|
|
|
|
namespace clang::tidy {
|
|
|
|
// Register the module using this statically initialized variable.
|
|
static ClangTidyModuleRegistry::Add<::NlohmannJsonChecksModule> nlohmannJsonChecksInit(
|
|
"nlohmann-json-checks-module",
|
|
"Adds 'modernize-nlohmann-json-explicit-conversions' check.");
|
|
|
|
} // namespace clang::tidy
|