[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
diff --git a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
index d02972d..138240a 100644
--- a/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/FunctionSizeCheck.cpp
@@ -72,12 +72,14 @@
     : 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 @@
     }
   }
 
+  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 @@
     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