unnecessary_final

Group: style

Maturity: stable

Dart SDK: >= 2.7.0 • (Linter v0.1.104)

Since info is static, may be stale
has-fix

View all Lint Rules

Using the Linter

Use var, not final, when declaring local variables.

Per Effective Dart, there are two styles in wide use. This rule enforces the var style. For the alternative style that prefers final, enable prefer_final_locals and prefer_final_in_for_each instead.

For fields, final is always recommended; see the rule prefer_final_fields.

BAD:

void badMethod() {
  final label = 'Final or var?';
  for (final char in ['v', 'a', 'r']) {
    print(char);
  }
}

GOOD:

void goodMethod() {
  var label = 'Final or var?';
  for (var char in ['v', 'a', 'r']) {
    print(char);
  }
}

Incompatible with: prefer_final_locals, prefer_final_parameters.

Usage

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

linter:
  rules:
    - unnecessary_final