10#include "clang/AST/ASTContext.h"
11#include "clang/ASTMatchers/ASTMatchFinder.h"
12#include "clang/ASTMatchers/ASTMatchers.h"
21 std::optional<StringRef> HeaderFileExtensionsOption =
23 RawStringHeaderFileExtensions =
25 if (HeaderFileExtensionsOption) {
30 << RawStringHeaderFileExtensions;
33 HeaderFileExtensions = Context->getHeaderFileExtensions();
38 Options.
store(Opts,
"HeaderFileExtensions", RawStringHeaderFileExtensions);
42 ast_matchers::MatchFinder *Finder) {
43 Finder->addMatcher(namespaceDecl(isAnonymous()).bind(
"anonymousNamespace"),
48 const MatchFinder::MatchResult &Result) {
49 const auto *N = Result.Nodes.getNodeAs<NamespaceDecl>(
"anonymousNamespace");
50 SourceLocation
Loc = N->getBeginLoc();
55 HeaderFileExtensions))
56 diag(
Loc,
"do not use unnamed namespaces in header files");
std::optional< StringRef > get(StringRef LocalName) const
Read a named option from the Context.
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, StringRef Value) const
Stores an option with the check-local name LocalName with string value Value to Options.
Base class for all clang-tidy checks.
DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning)
Add a diagnostic with the check's name.
DiagnosticBuilder configurationDiag(StringRef Description, DiagnosticIDs::Level Level=DiagnosticIDs::Warning) const
Adds a diagnostic to report errors in the check's configuration.
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
bool isPresumedLocInHeaderFile(SourceLocation Loc, SourceManager &SM, const FileExtensionsSet &HeaderFileExtensions)
Checks whether presumed location of Loc is in header file.
StringRef defaultHeaderFileExtensions()
Returns recommended default value for the list of header file extensions.
StringRef defaultFileExtensionDelimiters()
Returns recommended default value for the list of file extension delimiters.
bool parseFileExtensions(StringRef AllFileExtensions, FileExtensionsSet &FileExtensions, StringRef Delimiters)
Parses header file extensions from a semicolon-separated list.
llvm::StringMap< ClangTidyValue > OptionMap