annotate clang-tools-extra/clang-tidy/readability/FunctionCognitiveComplexityCheck.h @ 214:0cf2d4ade63d

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Tue, 13 Jul 2021 09:53:52 +0900
parents 2e18cbf3894f
children c4bab56944e8
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
207
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
1 //===--- FunctionCognitiveComplexityCheck.h - clang-tidy --------*- C++ -*-===//
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
2 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
4 // See https://llvm.org/LICENSE.txt for license information.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
6 //
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
7 //===----------------------------------------------------------------------===//
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
8
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
9 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONCOGNITIVECOMPLEXITYCHECK_H
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
10 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONCOGNITIVECOMPLEXITYCHECK_H
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
11
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
12 #include "../ClangTidyCheck.h"
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
13
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
14 namespace clang {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
15 namespace tidy {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
16 namespace readability {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
17
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
18 /// Checks function Cognitive Complexity metric.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
19 ///
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
20 /// There are the following configuration option:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
21 ///
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
22 /// * `Threshold` - flag functions with Cognitive Complexity exceeding
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
23 /// this number. The default is `25`.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
24 /// * `DescribeBasicIncrements`- if set to `true`, then for each function
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
25 /// exceeding the complexity threshold the check will issue additional
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
26 /// diagnostics on every piece of code (loop, `if` statement, etc.) which
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
27 /// contributes to that complexity.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
28 // Default is `true`
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
29 /// * `IgnoreMacros` - if set to `true`, the check will ignore code inside
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
30 /// macros. Default is `false`.
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
31 ///
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
32 /// For the user-facing documentation see:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
33 /// http://clang.llvm.org/extra/clang-tidy/checks/readability-function-cognitive-complexity.html
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
34 class FunctionCognitiveComplexityCheck : public ClangTidyCheck {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
35 public:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
36 FunctionCognitiveComplexityCheck(StringRef Name, ClangTidyContext *Context);
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
37
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
38 void storeOptions(ClangTidyOptions::OptionMap &Opts) override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
39 void registerMatchers(ast_matchers::MatchFinder *Finder) override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
40 void check(const ast_matchers::MatchFinder::MatchResult &Result) override;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
41 llvm::Optional<TraversalKind> getCheckTraversalKind() const override {
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
42 return TK_IgnoreUnlessSpelledInSource;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
43 }
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
44
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
45 private:
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
46 const unsigned Threshold;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
47 const bool DescribeBasicIncrements;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
48 const bool IgnoreMacros;
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
49 };
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
50
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
51 } // namespace readability
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
52 } // namespace tidy
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
53 } // namespace clang
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
54
Shinji KONO <kono@ie.u-ryukyu.ac.jp>
parents:
diff changeset
55 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_READABILITY_FUNCTIONCOGNITIVECOMPLEXITYCHECK_H