UsingNamespaceDirectiveCheck.h 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. //===--- UsingNamespaceDirectiveCheck.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_USINGNAMESPACEDIRECTIVECHECK_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_USINGNAMESPACEDIRECTIVECHECK_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::google::build {
  12. /// Finds using namespace directives.
  13. ///
  14. /// https://google.github.io/styleguide/cppguide.html#Namespaces
  15. ///
  16. /// The check implements the following rule of the Google C++ Style Guide:
  17. ///
  18. /// You may not use a using-directive to make all names from a namespace
  19. /// available.
  20. ///
  21. /// \code
  22. /// // Forbidden -- This pollutes the namespace.
  23. /// using namespace foo;
  24. /// \endcode
  25. ///
  26. /// Corresponding cpplint.py check name: `build/namespaces`.
  27. ///
  28. /// For the user-facing documentation see:
  29. /// https://clang.llvm.org/extra/clang-tidy/checks/google/build-using-namespace.html
  30. class UsingNamespaceDirectiveCheck : public ClangTidyCheck {
  31. public:
  32. UsingNamespaceDirectiveCheck(StringRef Name, ClangTidyContext *Context)
  33. : ClangTidyCheck(Name, Context) {}
  34. bool isLanguageVersionSupported(const LangOptions &LangOpts) const override {
  35. return LangOpts.CPlusPlus;
  36. }
  37. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  38. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  39. private:
  40. static bool isStdLiteralsNamespace(const NamespaceDecl *NS);
  41. };
  42. } // namespace clang::tidy::google::build
  43. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_GOOGLE_USINGNAMESPACEDIRECTIVECHECK_H