Rules / Complexity / max-parameters-for-function

max-parameters-for-function

lint/complexity/max-parameters-for-function
recommended
Same as max_parameters_for_function · Pyramid Lint

Flags a function, method, or operator 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 all positional, optional, and named parameters. Matching dart_code_linter's number-of-parameters metric, constructors are not counted — so wide named-parameter constructors, the dominant Flutter and DI pattern, are exempt — and copyWith methods are skipped.

Options

max_parameters (integer, default: 5) — flag when the parameter count exceeds this.

Invalid

example.dartdart
// 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');
}
Function has too many parameters (max 5).
1// Bad: function with 6 parameters exceeds max (default: 5)
2void create(String a, String b, int c, double d, bool e, List<String> f) {
Function has too many parameters (max 5).
12class Example {
13 void process(int p1, int p2, int p3, int p4, int p5, int p6, int p7) {
Function has too many parameters (max 5).
18 // Another method with 8 parameters
19 String buildString(String a, String b, int c, double d, bool e, List<String> f, Map<String, int> g, Set<int> h) {
Function has too many parameters (max 5).
24// Bad: top-level function with 6 parameters
25void configure(int x, int y, int z, double scale, bool enabled, String name) {

Valid

example.dartdart
// 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');
}

// dcl's number-of-parameters metric supports only functions and methods, never
// constructors — so a wide named-parameter constructor is never counted.
class Wide {
  final int a, b, c, d, e, f, g;

  const Wide({
    required this.a,
    required this.b,
    required this.c,
    required this.d,
    required this.e,
    required this.f,
    required this.g,
  });

  // `copyWith` returning the same class is explicitly exempt.
  Wide copyWith({int? a, int? b, int? c, int? d, int? e, int? f, int? g}) {
    return this;
  }
}

How to configure

Set the severity of max-parameters-for-function in your falcon.json:

falcon.jsonjson
{
  "linter": {
    "rules": {
      "complexity": {
        "max-parameters-for-function": "error"
      }
    }
  }
}