Skip to main content

avoid_final_parameters

Learn about the avoid_final_parameters linter rule.

Stable

Avoid final for parameter declarations.

Details

#

AVOID declaring parameters as final.

Declaring parameters as final can lead to unnecessarily verbose code, especially when using the "parameter_assignments" rule.

BAD:

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

GOOD:

dart
void badParameter(String label) { // OK  print(label); } 

BAD:

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

GOOD:

dart
void badExpression(int value) => print(value); // OK 

BAD:

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

GOOD:

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

Incompatible rules

#

The avoid_final_parameters lint is incompatible with the following rules:

Enable

#

To enable the avoid_final_parameters rule, add avoid_final_parameters under linter > rules in your analysis_options.yaml file:

analysis_options.yaml
yaml
linter:  rules:  - avoid_final_parameters 

If you're instead using the YAML map syntax to configure linter rules, add avoid_final_parameters: true under linter > rules:

analysis_options.yaml
yaml
linter:  rules:  avoid_final_parameters: true