NoNamespaceCheck.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. //===--- NoNamespaceCheck.cpp - clang-tidy---------------------------------===//
  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. #include "NoNamespaceCheck.h"
  9. #include "AbseilMatcher.h"
  10. #include "clang/AST/ASTContext.h"
  11. #include "clang/ASTMatchers/ASTMatchFinder.h"
  12. using namespace clang::ast_matchers;
  13. namespace clang::tidy::abseil {
  14. void NoNamespaceCheck::registerMatchers(MatchFinder *Finder) {
  15. Finder->addMatcher(
  16. namespaceDecl(hasName("::absl"), unless(isInAbseilFile()))
  17. .bind("abslNamespace"),
  18. this);
  19. }
  20. void NoNamespaceCheck::check(const MatchFinder::MatchResult &Result) {
  21. const auto *AbslNamespaceDecl =
  22. Result.Nodes.getNodeAs<NamespaceDecl>("abslNamespace");
  23. diag(AbslNamespaceDecl->getLocation(),
  24. "namespace 'absl' is reserved for implementation of the Abseil library "
  25. "and should not be opened in user code");
  26. }
  27. } // namespace clang::tidy::abseil