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