33 lines · cpp
1//===----------------------------------------------------------------------===//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-exception6//7//===----------------------------------------------------------------------===//8 9#include "NoNamespaceCheck.h"10#include "AbseilMatcher.h"11#include "clang/ASTMatchers/ASTMatchFinder.h"12 13using namespace clang::ast_matchers;14 15namespace clang::tidy::abseil {16 17void NoNamespaceCheck::registerMatchers(MatchFinder *Finder) {18 Finder->addMatcher(namespaceDecl(hasName("::absl"), unless(isInAbseilFile()))19 .bind("abslNamespace"),20 this);21}22 23void NoNamespaceCheck::check(const MatchFinder::MatchResult &Result) {24 const auto *AbslNamespaceDecl =25 Result.Nodes.getNodeAs<NamespaceDecl>("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::abseil33