xref: /llvm-project/clang-tools-extra/clang-tidy/google/UsingNamespaceDirectiveCheck.cpp (revision ed824e0e4b1f45159aafd032421e3c81ab76db1b)
1 //===--- UsingNamespaceDirectiveCheck.cpp - clang-tidy ----------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "UsingNamespaceDirectiveCheck.h"
11 #include "clang/AST/ASTContext.h"
12 #include "clang/ASTMatchers/ASTMatchFinder.h"
13 #include "clang/ASTMatchers/ASTMatchers.h"
14 
15 using namespace clang::ast_matchers;
16 
17 namespace clang {
18 namespace tidy {
19 namespace google {
20 namespace build {
21 
22 void UsingNamespaceDirectiveCheck::registerMatchers(
23     ast_matchers::MatchFinder *Finder) {
24   Finder->addMatcher(usingDirectiveDecl().bind("usingNamespace"), this);
25 }
26 
27 void
28 UsingNamespaceDirectiveCheck::check(const MatchFinder::MatchResult &Result) {
29   const auto *U = Result.Nodes.getNodeAs<UsingDirectiveDecl>("usingNamespace");
30   SourceLocation Loc = U->getLocStart();
31   if (U->isImplicit() || !Loc.isValid())
32     return;
33 
34   diag(Loc, "do not use namespace using-directives. Use using-declarations "
35             "instead.");
36   // TODO: We could suggest a list of using directives replacing the using
37   //       namespace directive.
38 }
39 
40 } // namespace build
41 } // namespace google
42 } // namespace tidy
43 } // namespace clang
44