avoid-final-parameters
Same as avoid_final_parameters in Dart lints
- Group
- Style
- Path
lint/style/avoid-final-parameters- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 65 of 512
Flags parameters declared final.
Parameters are rarely reassigned, and marking them final adds noise to
every signature without telling readers much. The final keyword is
reported on any parameter of a function, method, constructor, setter,
function literal, or function-typed parameter:
void f(final int x) {} // flagged
void g(int x) {} // fine
Initializing formals (final this.x, final super.x) and function-typed
parameters (final void cb()) are not reported, and Function(...) types
cannot declare final parameters at all. From Dart 3.13, where final
marks a declaring primary-constructor parameter, the rule is inactive.
Invalid
// @dart = 3.12
void f(final int x) {}
void g(int a, [final int b = 0]) {}
void h({final String? name}) {}
void i({required final String id}) {}
class A {
A(final int value);
void m(final x) {}
set value(final int v) {}
int operator +(final int other) => other;
}
void j() {
void local(final int x) {}
final literal = (final int y) => y;
local(1);
literal(2);
} void f(final int x) {} void g(int a, [final int b = 0]) {} void h({final String? name}) {} void i({required final String id}) {}class A { A(final int value); void m(final x) {} set value(final int v) {} int operator +(final int other) => other;void j() { void local(final int x) {} void local(final int x) {} final literal = (final int y) => y;Valid
void f(int x) {}
void g(int a, [int b = 0]) {}
void h({String? name}) {}
class A {
final int value;
final int other;
// Initializing formals may be final.
A(final this.value, this.other);
void m(int x) {
final y = x;
print(y);
}
set setter(int v) {}
}
class B extends A {
// Super parameters may be final.
B(final super.value, super.other);
}
// Function-typed parameters are not reported.
void callback(final void cb()) {}
void j() {
final local = 1;
print(local);
}Configure avoid-final-parameters
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-final-parameters": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-final-parameters: <reason>More style rules
- avoid-implementing-value-types
avoid_implementing_value_typesFlags
implementsof a class that overrides==. - avoid-init-to-null
avoid_init_to_nullrecommendedFlags explicit
= nullinitializers on declarations that already default to null. - avoid-js-rounded-ints
avoid_js_rounded_intsrecommendedAvoid integer literals that JavaScript would round.
- avoid-late-keyword
avoid-late-keywordFlags use of the
latekeyword on variables and fields. - avoid-multiple-declarations-per-line
avoid_multiple_declarations_per_linerecommendedFlags a variable declaration that declares more than one variable.
- avoid-non-null-assertion
avoid-non-null-assertionFlags the null-assertion operator
!except on a resolvedMapindex. - avoid-null-checks-in-equality-operators
avoid_null_checks_in_equality_operatorsrecommendedFlags null checks of the parameter inside a custom
operator ==. - avoid-positional-boolean-parameters
avoid_positional_boolean_parametersFlags a positional
boolparameter in a public signature.