prefer_final_parameters

Group: style

Maturity: stable

Linter vnull

Since info is static, may be stale

View all Lint Rules

Using the Linter

DO prefer declaring parameters as final if they are not reassigned in the function body.

Declaring parameters as final when possible is a good practice because it helps avoid accidental reassignments.

BAD:

void badParameter(String label) { // LINT
  print(label);
}

GOOD:

void goodParameter(final String label) { // OK
  print(label);
}

BAD:

void badExpression(int value) => print(value); // LINT

GOOD:

void goodExpression(final int value) => print(value); // OK

BAD:

[1, 4, 6, 8].forEach((value) => print(value + 2)); // LINT

GOOD:

[1, 4, 6, 8].forEach((final value) => print(value + 2)); // OK

GOOD:

void mutableParameter(String label) { // OK
  print(label);
  label = 'Hello Linter!';
  print(label);
}

Incompatible with: unnecessary_final.