[clang-tidy] Implement storeOptions for checks missing it.
authorNathan James <n.james93@hotmail.co.uk>
Sun, 21 Jun 2020 18:01:09 +0000 (19:01 +0100)
committerNathan James <n.james93@hotmail.co.uk>
Sun, 21 Jun 2020 18:01:11 +0000 (19:01 +0100)
Just adds the storeOptions for Checks that weren't already storing their options.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D82223

27 files changed:
clang-tools-extra/clang-tidy/bugprone/TooSmallLoopVariableCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.h
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.cpp
clang-tools-extra/clang-tidy/cppcoreguidelines/NarrowingConversionsCheck.h
clang-tools-extra/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.cpp
clang-tools-extra/clang-tidy/misc/NonPrivateMemberVariablesInClassesCheck.h
clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.cpp
clang-tools-extra/clang-tidy/misc/ThrowByValueCatchByReferenceCheck.h
clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.cpp
clang-tools-extra/clang-tidy/modernize/AvoidBindCheck.h
clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp
clang-tools-extra/clang-tidy/modernize/RawStringLiteralCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseAutoCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseBoolLiteralsCheck.h
clang-tools-extra/clang-tidy/modernize/UseEmplaceCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseTransparentFunctorsCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.cpp
clang-tools-extra/clang-tidy/modernize/UseUsingCheck.h
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.cpp
clang-tools-extra/clang-tidy/readability/MagicNumbersCheck.h
clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.cpp
clang-tools-extra/clang-tidy/readability/RedundantDeclarationCheck.h
clang-tools-extra/clang-tidy/readability/StaticAccessedThroughInstanceCheck.h
clang-tools-extra/clang-tidy/utils/HeaderGuard.cpp
clang-tools-extra/clang-tidy/utils/HeaderGuard.h

index be5a469..06332af 100644 (file)
@@ -30,8 +30,7 @@ static constexpr llvm::StringLiteral LoopIncrementName =
 TooSmallLoopVariableCheck::TooSmallLoopVariableCheck(StringRef Name,
                                                      ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context),
-      MagnitudeBitsUpperLimit(Options.get<unsigned>(
-          "MagnitudeBitsUpperLimit", 16)) {}
+      MagnitudeBitsUpperLimit(Options.get("MagnitudeBitsUpperLimit", 16U)) {}
 
 void TooSmallLoopVariableCheck::storeOptions(
     ClangTidyOptions::OptionMap &Opts) {
index a5756ff..608df8a 100644 (file)
@@ -29,6 +29,12 @@ InitVariablesCheck::InitVariablesCheck(StringRef Name,
                                             utils::IncludeSorter::IS_LLVM)),
       MathHeader(Options.get("MathHeader", "math.h")) {}
 
+void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IncludeStyle", IncludeStyle,
+                utils::IncludeSorter::getMapping());
+  Options.store(Opts, "MathHeader", MathHeader);
+}
+
 void InitVariablesCheck::registerMatchers(MatchFinder *Finder) {
   std::string BadDecl = "badDecl";
   Finder->addMatcher(
@@ -102,7 +108,6 @@ void InitVariablesCheck::check(const MatchFinder::MatchResult &Result) {
     }
   }
 }
-
 } // namespace cppcoreguidelines
 } // namespace tidy
 } // namespace clang
index 0cacf9e..61521b1 100644 (file)
@@ -24,6 +24,7 @@ namespace cppcoreguidelines {
 class InitVariablesCheck : public ClangTidyCheck {
 public:
   InitVariablesCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
                            Preprocessor *ModuleExpanderPP) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
index 2ae21a3..aa860b3 100644 (file)
@@ -29,6 +29,13 @@ NarrowingConversionsCheck::NarrowingConversionsCheck(StringRef Name,
           Options.get("WarnOnFloatingPointNarrowingConversion", true)),
       PedanticMode(Options.get("PedanticMode", false)) {}
 
+void NarrowingConversionsCheck::storeOptions(
+    ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "WarnOnFloatingPointNarrowingConversion",
+                WarnOnFloatingPointNarrowingConversion);
+  Options.store(Opts, "PedanticMode", PedanticMode);
+}
+
 void NarrowingConversionsCheck::registerMatchers(MatchFinder *Finder) {
   // ceil() and floor() are guaranteed to return integers, even though the type
   // is not integral.
@@ -442,7 +449,6 @@ void NarrowingConversionsCheck::check(const MatchFinder::MatchResult &Result) {
     return handleImplicitCast(*Result.Context, *Cast);
   llvm_unreachable("must be binary operator or cast expression");
 }
-
 } // namespace cppcoreguidelines
 } // namespace tidy
 } // namespace clang
index cc598ed..6a9f38b 100644 (file)
@@ -25,6 +25,8 @@ class NarrowingConversionsCheck : public ClangTidyCheck {
 public:
   NarrowingConversionsCheck(StringRef Name, ClangTidyContext *Context);
 
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
+
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
index 5b69885..ed736d1 100644 (file)
@@ -48,6 +48,14 @@ NonPrivateMemberVariablesInClassesCheck::
       IgnorePublicMemberVariables(
           Options.get("IgnorePublicMemberVariables", false)) {}
 
+void NonPrivateMemberVariablesInClassesCheck::storeOptions(
+    ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreClassesWithAllMemberVariablesBeingPublic",
+                IgnoreClassesWithAllMemberVariablesBeingPublic);
+  Options.store(Opts, "IgnorePublicMemberVariables",
+                IgnorePublicMemberVariables);
+}
+
 void NonPrivateMemberVariablesInClassesCheck::registerMatchers(
     MatchFinder *Finder) {
   // We can ignore structs/classes with all member variables being public.
index 70658e1..b50872c 100644 (file)
@@ -33,6 +33,7 @@ public:
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
     return LangOpts.CPlusPlus;
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
index 02cbf27..a63598f 100644 (file)
@@ -23,7 +23,9 @@ ThrowByValueCatchByReferenceCheck::ThrowByValueCatchByReferenceCheck(
       CheckAnonymousTemporaries(Options.get("CheckThrowTemporaries", true)),
       WarnOnLargeObject(Options.get("WarnOnLargeObject", false)),
       // Cannot access `ASTContext` from here so set it to an extremal value.
-      MaxSize(Options.get("MaxSize", std::numeric_limits<uint64_t>::max())) {}
+      MaxSizeOptions(
+          Options.get("MaxSize", std::numeric_limits<uint64_t>::max())),
+      MaxSize(MaxSizeOptions) {}
 
 void ThrowByValueCatchByReferenceCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(cxxThrowExpr().bind("throw"), this);
@@ -33,6 +35,8 @@ void ThrowByValueCatchByReferenceCheck::registerMatchers(MatchFinder *Finder) {
 void ThrowByValueCatchByReferenceCheck::storeOptions(
     ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "CheckThrowTemporaries", true);
+  Options.store(Opts, "WarnOnLargeObjects", WarnOnLargeObject);
+  Options.store(Opts, "MaxSize", MaxSizeOptions);
 }
 
 void ThrowByValueCatchByReferenceCheck::check(
index fdee9a0..3018fda 100644 (file)
@@ -45,6 +45,7 @@ private:
   bool isFunctionOrCatchVar(const DeclRefExpr *declRefExpr);
   const bool CheckAnonymousTemporaries;
   const bool WarnOnLargeObject;
+  const uint64_t MaxSizeOptions; // The raw value read from the options.
   uint64_t MaxSize; // No `const` because we have to set it in two steps.
 };
 
index b45d9c5..37f9eb6 100644 (file)
@@ -578,6 +578,10 @@ AvoidBindCheck::AvoidBindCheck(StringRef Name, ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context),
       PermissiveParameterList(Options.get("PermissiveParameterList", false)) {}
 
+void AvoidBindCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "PermissiveParameterList", PermissiveParameterList);
+}
+
 void AvoidBindCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
       callExpr(
index 8a8a1d1..d52c33a 100644 (file)
@@ -27,6 +27,7 @@ public:
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
     return LangOpts.CPlusPlus14;
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
index be3a714..dd18d86 100644 (file)
@@ -476,7 +476,7 @@ LoopConvertCheck::RangeDescriptor::RangeDescriptor()
 
 LoopConvertCheck::LoopConvertCheck(StringRef Name, ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context), TUInfo(new TUTrackingInfo),
-      MaxCopySize(std::stoull(Options.get("MaxCopySize", "16"))),
+      MaxCopySize(Options.get("MaxCopySize", 16ULL)),
       MinConfidence(Options.get("MinConfidence", getConfidenceMapping(),
                                 Confidence::CL_Reasonable)),
       NamingStyle(Options.get("NamingStyle", getStyleMapping(),
index fa0313f..7990bc2 100644 (file)
@@ -111,10 +111,9 @@ RawStringLiteralCheck::RawStringLiteralCheck(StringRef Name,
     DisallowedChars.set(static_cast<unsigned char>(C));
 }
 
-void RawStringLiteralCheck::storeOptions(ClangTidyOptions::OptionMap &Options) {
-  ClangTidyCheck::storeOptions(Options);
-  this->Options.store(Options, "ReplaceShorterLiterals",
-                      ReplaceShorterLiterals);
+void RawStringLiteralCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "DelimiterStem", DelimiterStem);
+  Options.store(Opts, "ReplaceShorterLiterals", ReplaceShorterLiterals);
 }
 
 void RawStringLiteralCheck::registerMatchers(MatchFinder *Finder) {
index eed9321..ecdef6a 100644 (file)
@@ -321,7 +321,7 @@ UseAutoCheck::UseAutoCheck(StringRef Name, ClangTidyContext *Context)
 
 void UseAutoCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
   Options.store(Opts, "MinTypeNameLength", MinTypeNameLength);
-  Options.store(Opts, "RemoveStars", RemoveStars ? 1 : 0);
+  Options.store(Opts, "RemoveStars", RemoveStars);
 }
 
 void UseAutoCheck::registerMatchers(MatchFinder *Finder) {
index 5ddda30..3dab743 100644 (file)
@@ -22,6 +22,10 @@ UseBoolLiteralsCheck::UseBoolLiteralsCheck(StringRef Name,
     : ClangTidyCheck(Name, Context),
       IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
 
+void UseBoolLiteralsCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+}
+
 void UseBoolLiteralsCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
       traverse(
index 8bbd739..486635b 100644 (file)
@@ -25,6 +25,7 @@ public:
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
     return LangOpts.CPlusPlus;
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
index 823b119..77d84bd 100644 (file)
@@ -160,6 +160,7 @@ void UseEmplaceCheck::check(const MatchFinder::MatchResult &Result) {
 }
 
 void UseEmplaceCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreImplicitConstructors", IgnoreImplicitConstructors);
   Options.store(Opts, "ContainersWithPushBack",
                 utils::options::serializeStringList(ContainersWithPushBack));
   Options.store(Opts, "SmartPointers",
index 6794254..cbd11f0 100644 (file)
@@ -22,7 +22,7 @@ UseTransparentFunctorsCheck::UseTransparentFunctorsCheck(
 
 void UseTransparentFunctorsCheck::storeOptions(
     ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "SafeMode", SafeMode ? 1 : 0);
+  Options.store(Opts, "SafeMode", SafeMode);
 }
 
 void UseTransparentFunctorsCheck::registerMatchers(MatchFinder *Finder) {
index f6dc5c0..f3e8506 100644 (file)
@@ -20,6 +20,10 @@ UseUsingCheck::UseUsingCheck(StringRef Name, ClangTidyContext *Context)
     : ClangTidyCheck(Name, Context),
       IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
 
+void UseUsingCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+}
+
 void UseUsingCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(typedefDecl(unless(isInstantiated())).bind("typedef"),
                      this);
@@ -111,7 +115,6 @@ void UseUsingCheck::check(const MatchFinder::MatchResult &Result) {
   std::string Replacement = Using + Name + " = " + Type;
   Diag << FixItHint::CreateReplacement(ReplaceRange, Replacement);
 }
-
 } // namespace modernize
 } // namespace tidy
 } // namespace clang
index b7fbf74..f116ff2 100644 (file)
@@ -32,9 +32,7 @@ public:
   bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
     return LangOpts.CPlusPlus11;
   }
-  void storeOptions(ClangTidyOptions::OptionMap &Opts) override {
-    Options.store(Opts, "IgnoreMacros", IgnoreMacros);
-  }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 };
index df2229a..1cecfa3 100644 (file)
@@ -67,11 +67,14 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
           Options.get("IgnoreAllFloatingPointValues", false)),
       IgnoreBitFieldsWidths(Options.get("IgnoreBitFieldsWidths", true)),
       IgnorePowersOf2IntegerValues(
-          Options.get("IgnorePowersOf2IntegerValues", false)) {
+          Options.get("IgnorePowersOf2IntegerValues", false)),
+      RawIgnoredIntegerValues(
+          Options.get("IgnoredIntegerValues", DefaultIgnoredIntegerValues)),
+      RawIgnoredFloatingPointValues(Options.get(
+          "IgnoredFloatingPointValues", DefaultIgnoredFloatingPointValues)) {
   // Process the set of ignored integer values.
   const std::vector<std::string> IgnoredIntegerValuesInput =
-      utils::options::parseStringList(
-          Options.get("IgnoredIntegerValues", DefaultIgnoredIntegerValues));
+      utils::options::parseStringList(RawIgnoredIntegerValues);
   IgnoredIntegerValues.resize(IgnoredIntegerValuesInput.size());
   llvm::transform(IgnoredIntegerValuesInput, IgnoredIntegerValues.begin(),
                   [](const std::string &Value) { return std::stoll(Value); });
@@ -80,8 +83,7 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
   if (!IgnoreAllFloatingPointValues) {
     // Process the set of ignored floating point values.
     const std::vector<std::string> IgnoredFloatingPointValuesInput =
-        utils::options::parseStringList(Options.get(
-            "IgnoredFloatingPointValues", DefaultIgnoredFloatingPointValues));
+        utils::options::parseStringList(RawIgnoredFloatingPointValues);
     IgnoredFloatingPointValues.reserve(IgnoredFloatingPointValuesInput.size());
     IgnoredDoublePointValues.reserve(IgnoredFloatingPointValuesInput.size());
     for (const auto &InputValue : IgnoredFloatingPointValuesInput) {
@@ -107,9 +109,14 @@ MagicNumbersCheck::MagicNumbersCheck(StringRef Name, ClangTidyContext *Context)
 }
 
 void MagicNumbersCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
-  Options.store(Opts, "IgnoredIntegerValues", DefaultIgnoredIntegerValues);
+  Options.store(Opts, "IgnoreAllFloatingPointValues",
+                IgnoreAllFloatingPointValues);
+  Options.store(Opts, "IgnoreBitFieldsWidths", IgnoreBitFieldsWidths);
+  Options.store(Opts, "IgnorePowersOf2IntegerValues",
+                IgnorePowersOf2IntegerValues);
+  Options.store(Opts, "IgnoredIntegerValues", RawIgnoredIntegerValues);
   Options.store(Opts, "IgnoredFloatingPointValues",
-                DefaultIgnoredFloatingPointValues);
+                RawIgnoredFloatingPointValues);
 }
 
 void MagicNumbersCheck::registerMatchers(MatchFinder *Finder) {
index 0cf7419..a53fa91 100644 (file)
@@ -86,6 +86,8 @@ private:
   const bool IgnoreAllFloatingPointValues;
   const bool IgnoreBitFieldsWidths;
   const bool IgnorePowersOf2IntegerValues;
+  const std::string RawIgnoredIntegerValues;
+  const std::string RawIgnoredFloatingPointValues;
 
   constexpr static unsigned SensibleNumberOfMagicValueExceptions = 16;
 
index ab2e15b..f673dad 100644 (file)
@@ -26,6 +26,11 @@ RedundantDeclarationCheck::RedundantDeclarationCheck(StringRef Name,
     : ClangTidyCheck(Name, Context),
       IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
 
+void RedundantDeclarationCheck::storeOptions(
+    ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "IgnoreMacros", IgnoreMacros);
+}
+
 void RedundantDeclarationCheck::registerMatchers(MatchFinder *Finder) {
   Finder->addMatcher(
       namedDecl(anyOf(varDecl(unless(isDefinition())),
@@ -81,7 +86,6 @@ void RedundantDeclarationCheck::check(const MatchFinder::MatchResult &Result) {
   }
   diag(Prev->getLocation(), "previously declared here", DiagnosticIDs::Note);
 }
-
 } // namespace readability
 } // namespace tidy
 } // namespace clang
index fbd0539..4b4b2a1 100644 (file)
@@ -22,6 +22,7 @@ namespace readability {
 class RedundantDeclarationCheck : public ClangTidyCheck {
 public:
   RedundantDeclarationCheck(StringRef Name, ClangTidyContext *Context);
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
   void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
 
index 42f8379..d12e821 100644 (file)
@@ -25,7 +25,7 @@ public:
   StaticAccessedThroughInstanceCheck(StringRef Name, ClangTidyContext *Context)
       : ClangTidyCheck(Name, Context),
         NameSpecifierNestingThreshold(
-            Options.get("NameSpecifierNestingThreshold", 3)) {}
+            Options.get("NameSpecifierNestingThreshold", 3U)) {}
 
   void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerMatchers(ast_matchers::MatchFinder *Finder) override;
index 1426fca..68bb987 100644 (file)
@@ -266,6 +266,10 @@ private:
 };
 } // namespace
 
+void HeaderGuardCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
+  Options.store(Opts, "HeaderFileExtensions", RawStringHeaderFileExtensions);
+}
+
 void HeaderGuardCheck::registerPPCallbacks(const SourceManager &SM,
                                            Preprocessor *PP,
                                            Preprocessor *ModuleExpanderPP) {
@@ -285,7 +289,6 @@ bool HeaderGuardCheck::shouldSuggestToAddHeaderGuard(StringRef FileName) {
 std::string HeaderGuardCheck::formatEndIf(StringRef HeaderGuard) {
   return "endif // " + HeaderGuard.str();
 }
-
 } // namespace utils
 } // namespace tidy
 } // namespace clang
index 7ce54f4..d3e09a3 100644 (file)
@@ -34,6 +34,7 @@ public:
                                HeaderFileExtensions,
                                utils::defaultFileExtensionDelimiters());
   }
+  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
   void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
                            Preprocessor *ModuleExpanderPP) override;