Skip to content

Commit e5de2a2

Browse files
authored
[clang-tidy][NFC] extract options verify to separately function (#120768)
1 parent c1e7e45 commit e5de2a2

File tree

3 files changed

+28
-22
lines changed

3 files changed

+28
-22
lines changed

clang-tools-extra/clang-tidy/ClangTidy.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,9 +646,9 @@ void exportReplacements(const llvm::StringRef MainFilePath,
646646
YAML << TUD;
647647
}
648648

649-
NamesAndOptions
649+
ChecksAndOptions
650650
getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
651-
NamesAndOptions Result;
651+
ChecksAndOptions Result;
652652
ClangTidyOptions Opts;
653653
Opts.Checks = "*";
654654
clang::tidy::ClangTidyContext Context(
@@ -661,7 +661,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
661661
}
662662

663663
for (const auto &Factory : Factories)
664-
Result.Names.insert(Factory.getKey());
664+
Result.Checks.insert(Factory.getKey());
665665

666666
#if CLANG_TIDY_ENABLE_STATIC_ANALYZER
667667
SmallString<64> Buffer(AnalyzerCheckNamePrefix);
@@ -670,7 +670,7 @@ getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers) {
670670
AllowEnablingAnalyzerAlphaCheckers)) {
671671
Buffer.truncate(DefSize);
672672
Buffer.append(AnalyzerCheck);
673-
Result.Names.insert(Buffer);
673+
Result.Checks.insert(Buffer);
674674
}
675675
for (std::string OptionName : {
676676
#define GET_CHECKER_OPTIONS

clang-tools-extra/clang-tidy/ClangTidy.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ class ClangTidyASTConsumerFactory {
5858
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
5959
bool AllowEnablingAnalyzerAlphaCheckers);
6060

61-
struct NamesAndOptions {
62-
llvm::StringSet<> Names;
61+
struct ChecksAndOptions {
62+
llvm::StringSet<> Checks;
6363
llvm::StringSet<> Options;
6464
};
6565

66-
NamesAndOptions
66+
ChecksAndOptions
6767
getAllChecksAndOptions(bool AllowEnablingAnalyzerAlphaCheckers = true);
6868

6969
/// Returns the effective check-specific options.

clang-tools-extra/clang-tidy/tool/ClangTidyMain.cpp

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -526,6 +526,24 @@ static bool verifyFileExtensions(
526526
return AnyInvalid;
527527
}
528528

529+
static bool verifyOptions(const llvm::StringSet<> &ValidOptions,
530+
const ClangTidyOptions::OptionMap &OptionMap,
531+
StringRef Source) {
532+
bool AnyInvalid = false;
533+
for (auto Key : OptionMap.keys()) {
534+
if (ValidOptions.contains(Key))
535+
continue;
536+
AnyInvalid = true;
537+
auto &Output = llvm::WithColor::warning(llvm::errs(), Source)
538+
<< "unknown check option '" << Key << '\'';
539+
llvm::StringRef Closest = closest(Key, ValidOptions);
540+
if (!Closest.empty())
541+
Output << "; did you mean '" << Closest << '\'';
542+
Output << VerifyConfigWarningEnd;
543+
}
544+
return AnyInvalid;
545+
}
546+
529547
static SmallString<256> makeAbsolute(llvm::StringRef Input) {
530548
if (Input.empty())
531549
return {};
@@ -629,29 +647,17 @@ int clangTidyMain(int argc, const char **argv) {
629647
if (VerifyConfig) {
630648
std::vector<ClangTidyOptionsProvider::OptionsSource> RawOptions =
631649
OptionsProvider->getRawOptions(FileName);
632-
NamesAndOptions Valid =
650+
ChecksAndOptions Valid =
633651
getAllChecksAndOptions(AllowEnablingAnalyzerAlphaCheckers);
634652
bool AnyInvalid = false;
635653
for (const auto &[Opts, Source] : RawOptions) {
636654
if (Opts.Checks)
637-
AnyInvalid |= verifyChecks(Valid.Names, *Opts.Checks, Source);
638-
655+
AnyInvalid |= verifyChecks(Valid.Checks, *Opts.Checks, Source);
639656
if (Opts.HeaderFileExtensions && Opts.ImplementationFileExtensions)
640657
AnyInvalid |=
641658
verifyFileExtensions(*Opts.HeaderFileExtensions,
642659
*Opts.ImplementationFileExtensions, Source);
643-
644-
for (auto Key : Opts.CheckOptions.keys()) {
645-
if (Valid.Options.contains(Key))
646-
continue;
647-
AnyInvalid = true;
648-
auto &Output = llvm::WithColor::warning(llvm::errs(), Source)
649-
<< "unknown check option '" << Key << '\'';
650-
llvm::StringRef Closest = closest(Key, Valid.Options);
651-
if (!Closest.empty())
652-
Output << "; did you mean '" << Closest << '\'';
653-
Output << VerifyConfigWarningEnd;
654-
}
660+
AnyInvalid |= verifyOptions(Valid.Options, Opts.CheckOptions, Source);
655661
}
656662
if (AnyInvalid)
657663
return 1;

0 commit comments

Comments
 (0)