1 //===--- BracesAroundStatementsCheck.h - clang-tidy -------------*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_BRACESAROUNDSTATEMENTSCHECK_H
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_BRACESAROUNDSTATEMENTSCHECK_H
12 #include "../ClangTidyCheck.h"
14 namespace clang::tidy::readability
{
16 /// Checks that bodies of `if` statements and loops (`for`, `range-for`,
17 /// `do-while`, and `while`) are inside braces
34 /// Additionally, one can define an option `ShortStatementLines` defining the
35 /// minimal number of lines that the statement should have in order to trigger
38 /// The number of lines is counted from the end of condition or initial keyword
39 /// (`do`/`else`) until the last line of the inner statement. Default value 0
40 /// means that braces will be added to all statements (not having them already).
41 class BracesAroundStatementsCheck
: public ClangTidyCheck
{
43 BracesAroundStatementsCheck(StringRef Name
, ClangTidyContext
*Context
);
44 void storeOptions(ClangTidyOptions::OptionMap
&Opts
) override
;
45 void registerMatchers(ast_matchers::MatchFinder
*Finder
) override
;
46 void check(const ast_matchers::MatchFinder::MatchResult
&Result
) override
;
47 void onEndOfTranslationUnit() override
;
50 bool checkStmt(const ast_matchers::MatchFinder::MatchResult
&Result
,
51 const Stmt
*S
, SourceLocation StartLoc
,
52 SourceLocation EndLocHint
= SourceLocation());
53 template <typename IfOrWhileStmt
>
54 SourceLocation
findRParenLoc(const IfOrWhileStmt
*S
, const SourceManager
&SM
,
55 const LangOptions
&LangOpts
);
56 std::optional
<TraversalKind
> getCheckTraversalKind() const override
{
57 return TK_IgnoreUnlessSpelledInSource
;
60 std::set
<const Stmt
*> ForceBracesStmts
;
61 const unsigned ShortStatementLines
;
64 } // namespace clang::tidy::readability
66 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_BRACESAROUNDSTATEMENTSCHECK_H