NonPrivateMemberVariablesInClassesCheck.h 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. //===--- NonPrivateMemberVariablesInClassesCheck.h - clang-tidy -*- C++ -*-===//
  2. //
  3. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  4. // See https://llvm.org/LICENSE.txt for license information.
  5. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  6. //
  7. //===----------------------------------------------------------------------===//
  8. #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONPRIVATEMEMBERVARIABLESINCLASSESCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONPRIVATEMEMBERVARIABLESINCLASSESCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::misc {
  12. /// This checker finds classes that not only contain the data
  13. /// (non-static member variables), but also have logic (non-static member
  14. /// functions), and diagnoses all member variables that have any other scope
  15. /// other than `private`. They should be made `private`, and manipulated
  16. /// exclusively via the member functions.
  17. ///
  18. /// Optionally, classes with all member variables being `public` could be
  19. /// ignored and optionally all `public` member variables could be ignored.
  20. ///
  21. /// For the user-facing documentation see:
  22. /// http://clang.llvm.org/extra/clang-tidy/checks/misc/non-private-member-variables-in-classes.html
  23. class NonPrivateMemberVariablesInClassesCheck : public ClangTidyCheck {
  24. public:
  25. NonPrivateMemberVariablesInClassesCheck(StringRef Name,
  26. ClangTidyContext *Context);
  27. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  28. return LangOpts.CPlusPlus;
  29. }
  30. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  31. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  32. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  33. private:
  34. const bool IgnoreClassesWithAllMemberVariablesBeingPublic;
  35. const bool IgnorePublicMemberVariables;
  36. };
  37. } // namespace clang::tidy::misc
  38. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_MISC_NONPRIVATEMEMBERVARIABLESINCLASSESCHECK_H