blob: 674292da1ee853dcd88e5579fb07569703bc3a82 [file] [log] [blame]
Olivier Deprezf4ef2d02021-04-20 13:36:24 +02001//===--- 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
15namespace clang {
16namespace tidy {
17namespace 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
38class SuspiciousIncludeCheck : public ClangTidyCheck {
39public:
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
45 utils::FileExtensionsSet HeaderFileExtensions;
46 utils::FileExtensionsSet ImplementationFileExtensions;
47
48private:
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