MisleadingIndentationCheck.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. //===--- MisleadingIndentationCheck.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_READABILITY_MISLEADING_INDENTATION_H
  9. #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADING_INDENTATION_H
  10. #include "../ClangTidyCheck.h"
  11. namespace clang::tidy::readability {
  12. /// Checks the code for dangling else, and possible misleading indentations due
  13. /// to missing braces. Note that this check only works as expected when the tabs
  14. /// or spaces are used consistently and not mixed.
  15. ///
  16. /// For the user-facing documentation see:
  17. /// http://clang.llvm.org/extra/clang-tidy/checks/readability/misleading-indentation.html
  18. class MisleadingIndentationCheck : public ClangTidyCheck {
  19. public:
  20. MisleadingIndentationCheck(StringRef Name, ClangTidyContext *Context)
  21. : ClangTidyCheck(Name, Context) {}
  22. void registerMatchers(ast_matchers::MatchFinder *Finder) override;
  23. void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
  24. std::optional<TraversalKind> getCheckTraversalKind() const override {
  25. return TK_IgnoreUnlessSpelledInSource;
  26. }
  27. private:
  28. void danglingElseCheck(const SourceManager &SM, ASTContext *Context,
  29. const IfStmt *If);
  30. void missingBracesCheck(const SourceManager &SM, const CompoundStmt *CStmt);
  31. };
  32. } // namespace clang::tidy::readability
  33. #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_MISLEADING_INDENTATION_H