Description
While working on extracting function metrics using the clang-tidy
checks readability-function-size
and readability-function-cognitive-complexity
, I noticed that the readability-function-size
check does not produce any output for lambda functions, but the readability-function-cognitive-complexity
check does.
For example, readability-function-cognitive-complexity
produces output for the following inline lambda function:
for_each_token(entry, [&](const std::string& s) {
const size_t pos = s.find("main");
if (pos != std::string::npos) {
found_main = true;
main_col = col_count;
}
++col_count;
});
showing a cognitive-complexity and nesting-level of 1, but the readability-function-size
check does not produce any output.
It would be nice to be able to get metrics about the number of lines, statements, branches, parameters and variables with lambda functions.
Also, it seems that the readability-function-size
check does not produce output for constructors with no statements in the body.
For example, the readability-function-size
check produces no output for the inline constructor:
class any {
public:
...
//! Copy constructor
any(const any & other)
: content(other.content ? other.content->clone() : 0)
{}
...
};
Now, that function has a non-zero number of parameters, so the readability-function-size
check should produce output showing that.
NOTE: I am using the following configuration file so these checks should produce output if any of these metrics are greater than zero:
Checks: '-*,readability-function-cognitive-complexity,readability-function-size'
CheckOptions:
- key: readability-function-cognitive-complexity.Threshold
value: '0'
- key: readability-function-cognitive-complexity.DescribeBasicIncrements
value: true
- key: readability-function-cognitive-complexity.IgnoreMacros
value: true
- 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: '0'
- key: readability-function-size.NestingThreshold
value: '0'
- key: readability-function-size.VariableThreshold
value: '0'