SuspiciousIncludeCheck.h 2.2 KB

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