Parameter count
The parameter count of a function is the number of parameters it declares. Past a handful of parameters, calls stop being readable: resize(800, 600, true, false, 2) says nothing, and two arguments of the same type can swap places without an error.
It is one of the five metrics of a function. A local function or a closure has a count of its own.
How it is counted
Section titled “How it is counted”Every declared parameter counts as one: positional, optional positional and named, required or not, this.x and super.x among them. A type parameter, the parameters of a function-typed parameter and an extension’s this do not count.
A getter has no parameter list, so its count is 0. A constructor with no body is not a function the metrics measure, so the properties a Flutter widget declares in such a constructor are not counted.
The page of the limit rule has every case: How the parameters are counted.
Example
Section titled “Example”String priceTag<T extends num>( T amount, String currency, { required String locale, bool showCents = true, String Function(T value, String symbol)? format,}) { final symbol = symbolOf(currency, locale); if (format != null) return format(amount, symbol); return showCents ? '$symbol ${amount.toStringAsFixed(2)}' : '$symbol ${amount.round()}';}Its parameter count is 5:
| Parameter | Counts |
|---|---|
amount, currency, positional |
2 |
locale, showCents, format, named |
3 |
the type parameter T |
0 |
value and symbol, the parameters of the function-typed parameter format |
0 |
The limit rule is max_parameters, advisory: a function whose value is over the limit max is a violation of it. A function exactly at max is not reported.
| Preset | Limit |
|---|---|
core |
none: the preset does not hold the rule |
recommended |
6 |
strict |
4 |
The example is under the limit of recommended and over the limit of strict.
To change the limit, set the rule’s max (Configuring metrics):
assay: rules: max_parameters: max: 8In the report
Section titled “In the report”assay metrics gives the metric a row in the box Metrics and a box of its own, with the limit and the counts on the right of its top line and the highest values first. assay metrics shows the report.
- JSON: the key
parameterCountof each function, with itsvalue, itslimitand whether it is over it. - HTML: the column Parameters of the table of functions.
- Trend: the series Parameter count over limit (Points and series).