diff options
| author | Alexander Kornienko <alexfh@google.com> | 2017-03-01 10:17:32 +0000 |
|---|---|---|
| committer | Alexander Kornienko <alexfh@google.com> | 2017-03-01 10:17:32 +0000 |
| commit | 9108644dbf54e4727728ab08c8b7e21bfcd12e8c (patch) | |
| tree | 8c99253407ef37f69e1a8229c42cccfbd08bd2a7 /clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp | |
| parent | eedf7ec07f40ab17fb8d77ed15ae27a65473856a (diff) | |
| download | bcm5719-llvm-9108644dbf54e4727728ab08c8b7e21bfcd12e8c.tar.gz bcm5719-llvm-9108644dbf54e4727728ab08c8b7e21bfcd12e8c.zip | |
[clang-tidy] Add parametercount for readibility-function-size
Summary:
Add an option to function-size to warn about high parameter counts.
This might be relevant for cppcoreguidelines and the safety module as well. Since the safety module is not landed in master already, i did not create an alias, but that can be done later as well.
Reviewers: sbenza, alexfh, hokein
Reviewed By: alexfh, hokein
Subscribers: JDevlieghere
Patch by Jonas Toth!
Differential Revision: https://reviews.llvm.org/D29561
llvm-svn: 296599
Diffstat (limited to 'clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp')
| -rw-r--r-- | clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp | 15 |
1 files changed, 13 insertions, 2 deletions
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp index d02972dde18..138240a3d87 100644 --- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp +++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp @@ -72,12 +72,14 @@ FunctionSizeCheck::FunctionSizeCheck(StringRef Name, ClangTidyContext *Context) : ClangTidyCheck(Name, Context), LineThreshold(Options.get("LineThreshold", -1U)), StatementThreshold(Options.get("StatementThreshold", 800U)), - BranchThreshold(Options.get("BranchThreshold", -1U)) {} + BranchThreshold(Options.get("BranchThreshold", -1U)), + ParameterThreshold(Options.get("ParameterThreshold", 6)) {} void FunctionSizeCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) { Options.store(Opts, "LineThreshold", LineThreshold); Options.store(Opts, "StatementThreshold", StatementThreshold); Options.store(Opts, "BranchThreshold", BranchThreshold); + Options.store(Opts, "ParameterThreshold", ParameterThreshold); } void FunctionSizeCheck::registerMatchers(MatchFinder *Finder) { @@ -103,8 +105,11 @@ void FunctionSizeCheck::check(const MatchFinder::MatchResult &Result) { } } + unsigned ActualNumberParameters = Func->getNumParams(); + if (FI.Lines > LineThreshold || FI.Statements > StatementThreshold || - FI.Branches > BranchThreshold) { + FI.Branches > BranchThreshold || + ActualNumberParameters > ParameterThreshold) { diag(Func->getLocation(), "function %0 exceeds recommended size/complexity thresholds") << Func; @@ -127,6 +132,12 @@ void FunctionSizeCheck::check(const MatchFinder::MatchResult &Result) { diag(Func->getLocation(), "%0 branches (threshold %1)", DiagnosticIDs::Note) << FI.Branches << BranchThreshold; } + + if (ActualNumberParameters > ParameterThreshold) { + diag(Func->getLocation(), "%0 parameters (threshold %1)", + DiagnosticIDs::Note) + << ActualNumberParameters << ParameterThreshold; + } } } // namespace readability |

