diff options
author | Roman Lebedev <lebedev.ri@gmail.com> | 2017-06-09 14:22:10 +0000 |
---|---|---|
committer | Roman Lebedev <lebedev.ri@gmail.com> | 2017-06-09 14:22:10 +0000 |
commit | a1cee29608a447ba40aacd979a8479b376ccde62 (patch) | |
tree | 0f5ce5684dd2c0cd03649e0e5825027b446a827f /clang-tools-extra/test/clang-tidy/readability-function-size.cpp | |
parent | 70db4246017d9ca310b9453fb2388977632e40a6 (diff) | |
download | bcm5719-llvm-a1cee29608a447ba40aacd979a8479b376ccde62.tar.gz bcm5719-llvm-a1cee29608a447ba40aacd979a8479b376ccde62.zip |
[clang-tidy] readability-function-size: add NestingThreshold param.
Summary:
Finds compound statements which create next nesting level after `NestingThreshold` and emits a warning.
Do note that it warns about each compound statement that breaches the threshold, but not any of it's sub-statements, to have readable warnings.
I was able to find only one coding style referencing nesting:
- https://www.kernel.org/doc/html/v4.10/process/coding-style.html#indentation
> In short, 8-char indents make things easier to read, and have the added benefit of warning you when you’re nesting your functions too deep.
This seems too basic, i'm not sure what else to test. Are more tests needed?
Reviewers: alexfh, aaron.ballman, sbenza
Reviewed By: alexfh, aaron.ballman
Subscribers: xazax.hun
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D32942
llvm-svn: 305082
Diffstat (limited to 'clang-tools-extra/test/clang-tidy/readability-function-size.cpp')
-rw-r--r-- | clang-tools-extra/test/clang-tidy/readability-function-size.cpp | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/clang-tools-extra/test/clang-tidy/readability-function-size.cpp b/clang-tools-extra/test/clang-tidy/readability-function-size.cpp index d98682c2b74..9a07eae7628 100644 --- a/clang-tools-extra/test/clang-tidy/readability-function-size.cpp +++ b/clang-tools-extra/test/clang-tidy/readability-function-size.cpp @@ -1,4 +1,4 @@ -// RUN: %check_clang_tidy %s readability-function-size %t -- -config='{CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}, {key: readability-function-size.ParameterThreshold, value: 5}]}' -- -std=c++11 +// RUN: %check_clang_tidy %s readability-function-size %t -- -config='{CheckOptions: [{key: readability-function-size.LineThreshold, value: 0}, {key: readability-function-size.StatementThreshold, value: 0}, {key: readability-function-size.BranchThreshold, value: 0}, {key: readability-function-size.ParameterThreshold, value: 5}, {key: readability-function-size.NestingThreshold, value: 2}]}' -- -std=c++11 // Bad formatting is intentional, don't run clang-format over the whole file! @@ -59,3 +59,33 @@ void bar2() { class A { void barx() {;;} }; } // // CHECK-MESSAGES: :[[@LINE-4]]:30: warning: function 'barx' exceeds recommended size/complexity // CHECK-MESSAGES: :[[@LINE-5]]:30: note: 2 statements (threshold 0) + +#define macro() {int x; {int y; {int z;}}} + +void baz0() { // 1 +// CHECK-MESSAGES: :[[@LINE-1]]:6: warning: function 'baz0' exceeds recommended size/complexity +// CHECK-MESSAGES: :[[@LINE-2]]:6: note: 9 statements (threshold 0) + int a; + { // 2 + int b; + { // 3 +// CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2) + int c; + { // 4 + int d; + } + } + } + { // 2 + int e; + } + { // 2 + { // 3 +// CHECK-MESSAGES: :[[@LINE-1]]:5: note: nesting level 3 starts here (threshold 2) + int j; + } + } + macro() +// CHECK-MESSAGES: :[[@LINE-1]]:3: note: nesting level 3 starts here (threshold 2) +// CHECK-MESSAGES: :[[@LINE-27]]:25: note: expanded from macro 'macro' +} |