[clang-tidy] remove never used IgnoreCase in option (#122573)

This commit is contained in:
Congcong Cai
2025-01-11 22:46:04 +08:00
committed by GitHub
parent ba58d35019
commit ae9bf17697
3 changed files with 18 additions and 27 deletions

View File

@@ -163,9 +163,10 @@ void ClangTidyCheck::OptionsView::store<bool>(
store(Options, LocalName, Value ? StringRef("true") : StringRef("false"));
}
std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
StringRef LocalName, ArrayRef<NameAndValue> Mapping, bool CheckGlobal,
bool IgnoreCase) const {
std::optional<int64_t>
ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
ArrayRef<NameAndValue> Mapping,
bool CheckGlobal) const {
if (!CheckGlobal && Context->getOptionsCollector())
Context->getOptionsCollector()->insert((NamePrefix + LocalName).str());
auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix,
@@ -178,12 +179,10 @@ std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
StringRef Closest;
unsigned EditDistance = 3;
for (const auto &NameAndEnum : Mapping) {
if (IgnoreCase) {
if (Value.equals_insensitive(NameAndEnum.second))
if (Value == NameAndEnum.second) {
return NameAndEnum.first;
} else if (Value == NameAndEnum.second) {
return NameAndEnum.first;
} else if (Value.equals_insensitive(NameAndEnum.second)) {
}
if (Value.equals_insensitive(NameAndEnum.second)) {
Closest = NameAndEnum.second;
EditDistance = 0;
continue;

View File

@@ -333,9 +333,9 @@ public:
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
get(StringRef LocalName, bool IgnoreCase = false) const {
get(StringRef LocalName) const {
if (std::optional<int64_t> ValueOr =
getEnumInt(LocalName, typeEraseMapping<T>(), false, IgnoreCase))
getEnumInt(LocalName, typeEraseMapping<T>(), false))
return static_cast<T>(*ValueOr);
return std::nullopt;
}
@@ -353,9 +353,9 @@ public:
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum_v<T>, T> get(StringRef LocalName, T Default,
bool IgnoreCase = false) const {
return get<T>(LocalName, IgnoreCase).value_or(Default);
std::enable_if_t<std::is_enum_v<T>, T> get(StringRef LocalName,
T Default) const {
return get<T>(LocalName).value_or(Default);
}
/// Read a named option from the ``Context`` and parse it as an
@@ -373,9 +373,9 @@ public:
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
getLocalOrGlobal(StringRef LocalName, bool IgnoreCase = false) const {
getLocalOrGlobal(StringRef LocalName) const {
if (std::optional<int64_t> ValueOr =
getEnumInt(LocalName, typeEraseMapping<T>(), true, IgnoreCase))
getEnumInt(LocalName, typeEraseMapping<T>(), true))
return static_cast<T>(*ValueOr);
return std::nullopt;
}
@@ -394,10 +394,9 @@ public:
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum_v<T>, T>
getLocalOrGlobal(StringRef LocalName, T Default,
bool IgnoreCase = false) const {
return getLocalOrGlobal<T>(LocalName, IgnoreCase).value_or(Default);
std::enable_if_t<std::is_enum_v<T>, T> getLocalOrGlobal(StringRef LocalName,
T Default) const {
return getLocalOrGlobal<T>(LocalName).value_or(Default);
}
/// Stores an option with the check-local name \p LocalName with
@@ -454,7 +453,7 @@ public:
std::optional<int64_t> getEnumInt(StringRef LocalName,
ArrayRef<NameAndValue> Mapping,
bool CheckGlobal, bool IgnoreCase) const;
bool CheckGlobal) const;
template <typename T>
std::enable_if_t<std::is_enum_v<T>, std::vector<NameAndValue>>

View File

@@ -417,13 +417,6 @@ TEST(ValidConfiguration, ValidEnumOptions) {
CHECK_VAL(TestCheck.getIntLocal<Colours>("Valid"), Colours::Red);
CHECK_VAL(TestCheck.getIntGlobal<Colours>("GlobalValid"), Colours::Violet);
CHECK_VAL(
TestCheck.getIntLocal<Colours>("ValidWrongCase", /*IgnoreCase*/ true),
Colours::Red);
CHECK_VAL(TestCheck.getIntGlobal<Colours>("GlobalValidWrongCase",
/*IgnoreCase*/ true),
Colours::Violet);
EXPECT_FALSE(TestCheck.getIntLocal<Colours>("ValidWrongCase").has_value());
EXPECT_FALSE(TestCheck.getIntLocal<Colours>("NearMiss").has_value());
EXPECT_FALSE(TestCheck.getIntGlobal<Colours>("GlobalInvalid").has_value());