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::tidy::bugprone { 16 17 /// Warns on inclusion of files whose names suggest that they're implementation 18 /// files, instead of headers. E.g: 19 /// 20 /// #include "foo.cpp" // warning 21 /// #include "bar.c" // warning 22 /// #include "baz.h" // no diagnostic 23 /// 24 /// The check supports these options: 25 /// - `HeaderFileExtensions`: a semicolon-separated list of filename 26 /// extensions of header files (The filename extensions should not contain 27 /// "." prefix) ";h;hh;hpp;hxx" by default. For extension-less header 28 /// files, using an empty string or leaving an empty string between ";" if 29 /// there are other filename extensions. 30 /// 31 /// - `ImplementationFileExtensions`: likewise, a semicolon-separated list of 32 /// filename extensions of implementation files. "c;cc;cpp;cxx" by default. 33 /// 34 /// For the user-facing documentation see: 35 /// http://clang.llvm.org/extra/clang-tidy/checks/bugprone/suspicious-include.html 36 class SuspiciousIncludeCheck : public ClangTidyCheck { 37 public: 38 SuspiciousIncludeCheck(StringRef Name, ClangTidyContext *Context); 39 void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, 40 Preprocessor *ModuleExpanderPP) override; 41 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 42 43 FileExtensionsSet HeaderFileExtensions; 44 FileExtensionsSet ImplementationFileExtensions; 45 46 private: 47 StringRef RawStringHeaderFileExtensions; 48 StringRef RawStringImplementationFileExtensions; 49 }; 50 51 } // namespace clang::tidy::bugprone 52 53 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_BUGPRONE_SUSPICIOUSINCLUDECHECK_H 54