Skip to content

Commit 5d1269d

Browse files
committed
[clang-tidy] add depercation warning for non-whitelisted global options
1 parent c858bf6 commit 5d1269d

File tree

3 files changed

+21
-12
lines changed

3 files changed

+21
-12
lines changed

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

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
//===----------------------------------------------------------------------===//
88

99
#include "ClangTidyCheck.h"
10-
#include "llvm/ADT/SmallString.h"
1110
#include "llvm/ADT/StringRef.h"
12-
#include "llvm/Support/Error.h"
11+
#include "llvm/ADT/StringSet.h"
1312
#include "llvm/Support/YAMLParser.h"
1413
#include <optional>
14+
#include <string>
1515

1616
namespace clang::tidy {
1717

@@ -62,16 +62,25 @@ ClangTidyCheck::OptionsView::get(StringRef LocalName) const {
6262
return std::nullopt;
6363
}
6464

65+
static const llvm::StringSet<> AllowedGlobalOption{"IncludeStyle"};
66+
6567
static ClangTidyOptions::OptionMap::const_iterator
6668
findPriorityOption(const ClangTidyOptions::OptionMap &Options,
6769
StringRef NamePrefix, StringRef LocalName,
68-
llvm::StringSet<> *Collector) {
70+
ClangTidyContext *Context) {
71+
llvm::StringSet<> *Collector = Context->getOptionsCollector();
6972
if (Collector) {
7073
Collector->insert((NamePrefix + LocalName).str());
7174
Collector->insert(LocalName);
7275
}
7376
auto IterLocal = Options.find((NamePrefix + LocalName).str());
7477
auto IterGlobal = Options.find(LocalName);
78+
// FIXME: temporary solution for deprecation warnings, should be removed
79+
// after 22.x.
80+
if (IterGlobal != Options.end() && !AllowedGlobalOption.contains(LocalName))
81+
Context->configurationDiag(
82+
"deprecation global option '%0', please use '%1%0'.")
83+
<< LocalName << NamePrefix;
7584
if (IterLocal == Options.end())
7685
return IterGlobal;
7786
if (IterGlobal == Options.end())
@@ -83,8 +92,7 @@ findPriorityOption(const ClangTidyOptions::OptionMap &Options,
8392

8493
std::optional<StringRef>
8594
ClangTidyCheck::OptionsView::getLocalOrGlobal(StringRef LocalName) const {
86-
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName,
87-
Context->getOptionsCollector());
95+
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context);
8896
if (Iter != CheckOptions.end())
8997
return StringRef(Iter->getValue().Value);
9098
return std::nullopt;
@@ -117,8 +125,7 @@ ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const {
117125
template <>
118126
std::optional<bool>
119127
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const {
120-
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName,
121-
Context->getOptionsCollector());
128+
auto Iter = findPriorityOption(CheckOptions, NamePrefix, LocalName, Context);
122129
if (Iter != CheckOptions.end()) {
123130
if (auto Result = getAsBool(Iter->getValue().Value, Iter->getKey()))
124131
return Result;
@@ -157,10 +164,9 @@ std::optional<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
157164
bool IgnoreCase) const {
158165
if (!CheckGlobal && Context->getOptionsCollector())
159166
Context->getOptionsCollector()->insert((NamePrefix + LocalName).str());
160-
auto Iter = CheckGlobal
161-
? findPriorityOption(CheckOptions, NamePrefix, LocalName,
162-
Context->getOptionsCollector())
163-
: CheckOptions.find((NamePrefix + LocalName).str());
167+
auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix,
168+
LocalName, Context)
169+
: CheckOptions.find((NamePrefix + LocalName).str());
164170
if (Iter == CheckOptions.end())
165171
return std::nullopt;
166172

clang-tools-extra/test/clang-tidy/checkers/modernize/use-std-format-fmt.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %check_clang_tidy %s modernize-use-std-format %t -- \
22
// RUN: -config="{CheckOptions: { \
3-
// RUN: StrictMode: true, \
3+
// RUN: modernize-use-std-format.StrictMode: true, \
44
// RUN: modernize-use-std-format.StrFormatLikeFunctions: 'fmt::sprintf', \
55
// RUN: modernize-use-std-format.ReplacementFormatFunction: 'fmt::format', \
66
// RUN: modernize-use-std-format.FormatHeader: '<fmt/core.h>' \
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
// RUN: clang-tidy %s --config="{CheckOptions:{StrictMode: true}}" -checks="-*,modernize-use-std-format" | FileCheck %s
2+
3+
// CHECK: warning: deprecation global option 'StrictMode', please use 'modernize-use-std-format.StrictMode'. [clang-tidy-config]

0 commit comments

Comments
 (0)