max-parameters-for-function
Same as max_parameters_for_function in Pyramid Lint
- Group
- Complexity
- Path
lint/complexity/max-parameters-for-function- Default
- Off, opt in
- Origin
- Pyramid Lint
- Rule
- 263 of 512
Flags callable declarations and function types with more than the configured number of parameters.
A long parameter list is hard to call correctly and usually signals that some arguments belong together in an object. The rule counts required, optional-positional, and named parameters on functions, local functions, closures, methods, constructors, operators, setters, and function types.
Options
max-parameters (integer, default: 5) — flag when the parameter count
exceeds this.
Invalid
// Bad: function with 6 parameters exceeds max (default: 5)
void create(String a, String b, int c, double d, bool e, List<String> f) {
print(a);
print(b);
print(c);
print(d);
print(e);
print(f);
}
// Bad: method with 7 parameters
class Example {
void process(int p1, int p2, int p3, int p4, int p5, int p6, int p7) {
print(p1);
print(p2);
}
// Another method with 8 parameters
String buildString(String a, String b, int c, double d, bool e, List<String> f, Map<String, int> g, Set<int> h) {
return '$a-$b-$c-$d-$e-${f.length}-${g.length}-${h.length}';
}
}
// Bad: top-level function with 6 parameters
void configure(int x, int y, int z, double scale, bool enabled, String name) {
print('$x, $y, $z, $scale, $enabled, $name');
}
class Wide {
Wide(int a, int b, int c, int d, int e, int f);
Wide copyWith({int? a, int? b, int? c, int? d, int? e, int? f}) => this;
}
typedef WideCallback = void Function(int a, int b, int c, int d, int e, int f);
void nested() {
void local(int a, int b, int c, int d, int e, int f) {}
final callback = (int a, int b, int c, int d, int e, int f) {};
}
void accepts(void callback(int a, int b, int c, int d, int e, int f)) {}// Bad: function with 6 parameters exceeds max (default: 5)void create(String a, String b, int c, double d, bool e, List<String> f) {class Example { void process(int p1, int p2, int p3, int p4, int p5, int p6, int p7) { // Another method with 8 parameters String buildString(String a, String b, int c, double d, bool e, List<String> f, Map<String, int> g, Set<int> h) {// Bad: top-level function with 6 parametersvoid configure(int x, int y, int z, double scale, bool enabled, String name) {class Wide { Wide(int a, int b, int c, int d, int e, int f); Wide copyWith({int? a, int? b, int? c, int? d, int? e, int? f}) => this; typedef WideCallback = void Function(int a, int b, int c, int d, int e, int f);void nested() { void local(int a, int b, int c, int d, int e, int f) {} void local(int a, int b, int c, int d, int e, int f) {} final callback = (int a, int b, int c, int d, int e, int f) {}; void accepts(void callback(int a, int b, int c, int d, int e, int f)) {}Valid
// Good: function with 3 parameters under limit
void create(String a, String b, int c) {
print(a);
print(b);
print(c);
}
// Good: using a config object instead of many parameters
class Config {
final String name;
final int count;
final double value;
final bool flag;
final List<String> items;
}
void configure(Config config) {
print(config.name);
}
// Good: method with 5 parameters (at limit)
class Example {
void process(int p1, int p2, int p3, int p4, int p5) {
print(p1);
}
// Good: constructor with 4 parameters
Example.simple(String name, int age, double height, bool active) {
}
// Good: single parameter
void singleParam(String value) {
print(value);
}
// Good: no parameters
void noParams() {
print('Called with no parameters');
}
}
// Good: optional parameters within limit
void functionalApproach({String? name, int? age, double? score, bool? flag}) {
print('$name, $age, $score, $flag');
}
class AtLimit {
final int a, b, c, d, e;
const AtLimit(this.a, this.b, this.c, this.d, this.e);
AtLimit copyWith({int? a, int? b, int? c, int? d, int? e}) => this;
}
typedef AtLimitCallback = void Function(int a, int b, int c, int d, int e);Configure max-parameters-for-function
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"complexity": {
"max-parameters-for-function": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/complexity/max-parameters-for-function: <reason>More complexity rules
- max-statements
Reports function bodies with too many statements.
- max-switch-cases
max_switch_casesFlags a
switchstatement with more than the configured number of cases. - maximum-nesting-level
maximum_nesting_levelFlags a function whose control-flow nesting runs deeper than the configured level.
- no-boolean-literal-compare
no-boolean-literal-comparerecommendedDon't compare boolean values to boolean literals.
- one-member-abstracts
one_member_abstractsFlags abstract classes whose only member is a single abstract method.
- prefer-conditional-assignment
prefer_conditional_assignmentrecommendedFlags
if (x == null) { x = y; }with no else branch. - prefer-conditional-expressions
prefer-conditional-expressionsFlags an
if/elsewhose branches each reduce to a single return or a single assignment to the same target. - prefer-expression-function-bodies
prefer_expression_function_bodiesFlags block function bodies that consist of a single
returnof a value.