2015-12-23 01:36:49 +08:00
|
|
|
.. title:: clang-tidy - readability-function-size
|
|
|
|
|
2015-08-28 02:10:07 +08:00
|
|
|
readability-function-size
|
|
|
|
=========================
|
|
|
|
|
2016-04-02 09:07:18 +08:00
|
|
|
`google-readability-function-size` redirects here as an alias for this check.
|
2015-08-28 02:10:07 +08:00
|
|
|
|
|
|
|
Checks for large functions based on various metrics.
|
|
|
|
|
2016-08-18 19:06:09 +08:00
|
|
|
Options
|
|
|
|
-------
|
|
|
|
|
|
|
|
.. option:: LineThreshold
|
|
|
|
|
|
|
|
Flag functions exceeding this number of lines. The default is `-1` (ignore
|
|
|
|
the number of lines).
|
|
|
|
|
|
|
|
.. option:: StatementThreshold
|
|
|
|
|
|
|
|
Flag functions exceeding this number of statements. This may differ
|
|
|
|
significantly from the number of lines for macro-heavy code. The default is
|
|
|
|
`800`.
|
|
|
|
|
|
|
|
.. option:: BranchThreshold
|
|
|
|
|
|
|
|
Flag functions exceeding this number of control statements. The default is
|
|
|
|
`-1` (ignore the number of branches).
|
2017-03-01 18:17:32 +08:00
|
|
|
|
|
|
|
.. option:: ParameterThreshold
|
|
|
|
|
2017-06-09 22:22:10 +08:00
|
|
|
Flag functions that exceed a specified number of parameters. The default
|
2017-03-09 17:15:16 +08:00
|
|
|
is `-1` (ignore the number of parameters).
|
2017-06-09 22:22:10 +08:00
|
|
|
|
|
|
|
.. option:: NestingThreshold
|
|
|
|
|
|
|
|
Flag compound statements which create next nesting level after
|
|
|
|
`NestingThreshold`. This may differ significantly from the expected value
|
|
|
|
for macro-heavy code. The default is `-1` (ignore the nesting level).
|
[clang-tidy] readability-function-size: add VariableThreshold param.
Summary:
Pretty straight-forward, just count all the variable declarations in the function's body, and if more than the configured threshold - do complain.
Note that this continues perverse practice of disabling the new option by default.
I'm not certain where is the balance point between not being too noisy, and actually enforcing the good practice.
If we really want to not disable this by default, but also to not cause too many new warnings, we could default to 50 or so.
But that is a lot of variables too...
I was able to find one coding style referencing variable count:
- https://www.kernel.org/doc/html/v4.15/process/coding-style.html#functions
> Another measure of the function is the number of local variables. They shouldn’t exceed 5-10, or you’re doing something wrong.
Reviewers: hokein, xazax.hun, JonasToth, aaron.ballman, alexfh
Reviewed By: aaron.ballman
Subscribers: kimgr, Eugene.Zelenko, rnkovacs, cfe-commits
Tags: #clang-tools-extra
Differential Revision: https://reviews.llvm.org/D44602
llvm-svn: 329902
2018-04-12 20:06:42 +08:00
|
|
|
|
|
|
|
.. option:: VariableThreshold
|
|
|
|
|
|
|
|
Flag functions exceeding this number of variables declared in the body.
|
|
|
|
The default is `-1` (ignore the number of variables).
|
|
|
|
Please note that function parameters and variables declared in lambdas,
|
|
|
|
GNU Statement Expressions, and nested class inline functions are not counted.
|