UnnamedNamespaceInHeaderCheck.h 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===--- UnnamedNamespaceInHeaderCheck.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_GOOGLE_UNNAMEDNAMESPACEINHEADERCHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_UNNAMEDNAMESPACEINHEADERCHECK_H
  10. #include "../ClangTidyCheck.h"
  11. #include "../utils/FileExtensionsUtils.h"
  12. namespace clang::tidy::google::build {
  13. /// Finds anonymous namespaces in headers.
  14. ///
  15. /// The check supports these options:
  16. /// - `HeaderFileExtensions`: a semicolon-separated list of filename
  17. /// extensions of header files (The filename extensions should not contain
  18. /// "." prefix). ";h;hh;hpp;hxx" by default.
  19. ///
  20. /// For extension-less header files, using an empty string or leaving an
  21. /// empty string between ";" if there are other filename extensions.
  22. ///
  23. /// https://google.github.io/styleguide/cppguide.html#Namespaces
  24. ///
  25. /// Corresponding cpplint.py check name: 'build/namespaces'.
  26. ///
  27. /// For the user-facing documentation see:
  28. /// http://clang.llvm.org/extra/clang-tidy/checks/google/build-namespaces.html
  29. class UnnamedNamespaceInHeaderCheck : public ClangTidyCheck {
  30. public:
  31. UnnamedNamespaceInHeaderCheck(StringRef Name, ClangTidyContext *Context);
  32. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  33. return LangOpts.CPlusPlus;
  34. }
  35. void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
  36. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  37. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  38. private:
  39. const StringRef RawStringHeaderFileExtensions;
  40. utils::FileExtensionsSet HeaderFileExtensions;
  41. };
  42. } // namespace clang::tidy::google::build
  43. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_UNNAMEDNAMESPACEINHEADERCHECK_H