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
1616namespace 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+
6567static ClangTidyOptions::OptionMap::const_iterator
6668findPriorityOption (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
8493std::optional<StringRef>
8594ClangTidyCheck::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 {
117125template <>
118126std::optional<bool >
119127ClangTidyCheck::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
0 commit comments