[clang-tidy][NFC] extract options verify to separately function (#120768)
This commit is contained in:
@@ -646,9 +646,9 @@ void exportReplacements(const llvm::StringRef MainFilePath,
|
||||
YAML << TUD;
|
||||
}
|
||||
|
||||
NamesAndOptions
|
||||
ChecksAndOptions
|
||||
getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
|
||||
NamesAndOptions Result;
|
||||
ChecksAndOptions Result;
|
||||
ClangTidyOptions Opts;
|
||||
Opts.Checks = "*";
|
||||
clang::tidy::ClangTidyContext Context(
|
||||
@@ -661,7 +661,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
|
||||
}
|
||||
|
||||
for (const auto &Factory : Factories)
|
||||
Result.Names.insert(Factory.getKey());
|
||||
Result.Checks.insert(Factory.getKey());
|
||||
|
||||
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
|
||||
SmallString<64> Buffer(AnalyzerCheckNamePrefix);
|
||||
@@ -670,7 +670,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
|
||||
AllowEnablingAnalyzerAlphaCheckers)) {
|
||||
Buffer.truncate(DefSize);
|
||||
Buffer.append(AnalyzerCheck);
|
||||
Result.Names.insert(Buffer);
|
||||
Result.Checks.insert(Buffer);
|
||||
}
|
||||
for (std::string OptionName : {
|
||||
#define GET_CHECKER_OPTIONS
|
||||
|
||||
@@ -58,12 +58,12 @@ private:
|
||||
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
|
||||
bool AllowEnablingAnalyzerAlphaCheckers);
|
||||
|
||||
struct NamesAndOptions {
|
||||
llvm::StringSet<> Names;
|
||||
struct ChecksAndOptions {
|
||||
llvm::StringSet<> Checks;
|
||||
llvm::StringSet<> Options;
|
||||
};
|
||||
|
||||
NamesAndOptions
|
||||
ChecksAndOptions
|
||||
getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true);
|
||||
|
||||
/// Returns the effective check-specific options.
|
||||
|
||||
@@ -526,6 +526,24 @@ static bool verifyFileExtensions(
|
||||
return AnyInvalid;
|
||||
}
|
||||
|
||||
static bool verifyOptions(const llvm::StringSet<> &ValidOptions,
|
||||
const ClangTidyOptions::OptionMap &OptionMap,
|
||||
StringRef Source) {
|
||||
bool AnyInvalid = false;
|
||||
for (auto Key : OptionMap.keys()) {
|
||||
if (ValidOptions.contains(Key))
|
||||
continue;
|
||||
AnyInvalid = true;
|
||||
auto &Output = llvm::WithColor::warning(llvm::errs(), Source)
|
||||
<< "unknown check option '" << Key << '\'';
|
||||
llvm::StringRef Closest = closest(Key, ValidOptions);
|
||||
if (!Closest.empty())
|
||||
Output << "; did you mean '" << Closest << '\'';
|
||||
Output << VerifyConfigWarningEnd;
|
||||
}
|
||||
return AnyInvalid;
|
||||
}
|
||||
|
||||
static SmallString<256> makeAbsolute(llvm::StringRef Input) {
|
||||
if (Input.empty())
|
||||
return {};
|
||||
@@ -629,29 +647,17 @@ int clangTidyMain(int argc, const char **argv) {
|
||||
if (VerifyConfig) {
|
||||
std::vector<ClangTidyOptionsProvider::OptionsSource> RawOptions =
|
||||
OptionsProvider->getRawOptions(FileName);
|
||||
NamesAndOptions Valid =
|
||||
ChecksAndOptions Valid =
|
||||
getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers);
|
||||
bool AnyInvalid = false;
|
||||
for (const auto &[Opts, Source] : RawOptions) {
|
||||
if (Opts.Checks)
|
||||
AnyInvalid |= verifyChecks(Valid.Names, *Opts.Checks, Source);
|
||||
|
||||
AnyInvalid |= verifyChecks(Valid.Checks, *Opts.Checks, Source);
|
||||
if (Opts.HeaderFileExtensions && Opts.ImplementationFileExtensions)
|
||||
AnyInvalid |=
|
||||
verifyFileExtensions(*Opts.HeaderFileExtensions,
|
||||
*Opts.ImplementationFileExtensions, Source);
|
||||
|
||||
for (auto Key : Opts.CheckOptions.keys()) {
|
||||
if (Valid.Options.contains(Key))
|
||||
continue;
|
||||
AnyInvalid = true;
|
||||
auto &Output = llvm::WithColor::warning(llvm::errs(), Source)
|
||||
<< "unknown check option '" << Key << '\'';
|
||||
llvm::StringRef Closest = closest(Key, Valid.Options);
|
||||
if (!Closest.empty())
|
||||
Output << "; did you mean '" << Closest << '\'';
|
||||
Output << VerifyConfigWarningEnd;
|
||||
}
|
||||
AnyInvalid |= verifyOptions(Valid.Options, Opts.CheckOptions, Source);
|
||||
}
|
||||
if (AnyInvalid)
|
||||
return 1;
|
||||
|
||||
Reference in New Issue
Block a user