clang-tools  14.0.0git
SuspiciousIncludeCheck.h
Go to the documentation of this file.
1 //===--- SuspiciousIncludeCheck.h - clang-tidy ------------------*- C++ -*-===//
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 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H
11 
12 #include "../ClangTidyCheck.h"
13 #include "../utils/FileExtensionsUtils.h"
14 
15 namespace clang {
16 namespace tidy {
17 namespace bugprone {
18 
19 /// Warns on inclusion of files whose names suggest that they're implementation
20 /// files, instead of headers. E.g:
21 ///
22 /// #include "foo.cpp" // warning
23 /// #include "bar.c" // warning
24 /// #include "baz.h" // no diagnostic
25 ///
26 /// The check supports these options:
27 /// - `HeaderFileExtensions`: a semicolon-separated list of filename
28 /// extensions of header files (The filename extensions should not contain
29 /// "." prefix) ";h;hh;hpp;hxx" by default. For extension-less header
30 /// files, using an empty string or leaving an empty string between ";" if
31 /// there are other filename extensions.
32 ///
33 /// - `ImplementationFileExtensions`: likewise, a semicolon-separated list of
34 /// filename extensions of implementation files. "c;cc;cpp;cxx" by default.
35 ///
36 /// For the user-facing documentation see:
37 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone-suspicious-include.html
39 public:
40  SuspiciousIncludeCheck(StringRef Name, ClangTidyContext *Context);
41  void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP,
42  Preprocessor *ModuleExpanderPP) override;
43  void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
44 
47 
48 private:
49  const std::string RawStringHeaderFileExtensions;
50  const std::string RawStringImplementationFileExtensions;
51 };
52 
53 } // namespace bugprone
54 } // namespace tidy
55 } // namespace clang
56 
57 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H
clang::tidy::ClangTidyOptions::OptionMap
llvm::StringMap< ClangTidyValue > OptionMap
Definition: ClangTidyOptions.h:115
clang::tidy::bugprone::SuspiciousIncludeCheck::SuspiciousIncludeCheck
SuspiciousIncludeCheck(StringRef Name, ClangTidyContext *Context)
Definition: SuspiciousIncludeCheck.cpp:38
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition: ClangTidyCheck.h:54
clang::tidy::bugprone::SuspiciousIncludeCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Should store all options supported by this check with their current values or default values for opti...
Definition: SuspiciousIncludeCheck.cpp:61
clang::tidy::bugprone::SuspiciousIncludeCheck::ImplementationFileExtensions
utils::FileExtensionsSet ImplementationFileExtensions
Definition: SuspiciousIncludeCheck.h:46
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition: ClangTidyDiagnosticConsumer.h:71
Name
static constexpr llvm::StringLiteral Name
Definition: UppercaseLiteralSuffixCheck.cpp:28
clang::tidy::bugprone::SuspiciousIncludeCheck::registerPPCallbacks
void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, Preprocessor *ModuleExpanderPP) override
Override this to register PPCallbacks in the preprocessor.
Definition: SuspiciousIncludeCheck.cpp:67
clang::tidy::bugprone::PP
static Preprocessor * PP
Definition: BadSignalToKillThreadCheck.cpp:29
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition: ApplyReplacements.h:27
SM
const SourceManager & SM
Definition: IncludeCleaner.cpp:140
clang::tidy::bugprone::SuspiciousIncludeCheck
Warns on inclusion of files whose names suggest that they're implementation files,...
Definition: SuspiciousIncludeCheck.h:38
clang::tidy::bugprone::SuspiciousIncludeCheck::HeaderFileExtensions
utils::FileExtensionsSet HeaderFileExtensions
Definition: SuspiciousIncludeCheck.h:45
clang::tidy::utils::FileExtensionsSet
llvm::SmallSet< llvm::StringRef, 5 > FileExtensionsSet
Definition: FileExtensionsUtils.h:22