overridden-fields

Same as overridden_fields in Dart lints

Path
lint/suspicious/overridden-fields
Default
On (recommended)
Origin
Dart lints
Rule
306 of 512
recommended

Flags instance fields that redeclare an inherited field.

A field is reported when its inherited concrete super implementation is a field — the first concrete getter-providing member of the superclass chain and mixin applications, or for a mixin the member of its on types' interfaces (Object without one). Fields reached only through implements, abstract members of superclasses, and fields shadowed by a nearer getter or method are not reported; covariance does not matter. Extension types inherit no concrete members. Declaring var/final primary constructor parameters are instance fields too; forwarding formals and ordinary header parameters are not declarations.

Invalid

example.dartdart
class Base { int value = 0; }
class Child extends Base {
  int value = 1;
}

mixin class Mixed { final int mixed = 0; }
class FromMixin with Mixed {
  final int mixed = 1;
}

class Covariant { covariant num value = 0; }
class FromCovariant extends Covariant {
  int value = 1;
}
Don't override inherited fields.
2class Child extends Base {
3 int value = 1;
Don't override inherited fields.
7class FromMixin with Mixed {
8 final int mixed = 1;
Don't override inherited fields.
12class FromCovariant extends Covariant {
13 int value = 1;

Valid

example.dartdart
abstract class Base { covariant num value; }
class Child implements Base { int value = 1; }
class Other extends Base { int another = 0; }

class InterfaceField { final int viaInterface = 0; }
class Implementer implements InterfaceField {
  @override
  final int viaInterface = 1;
}

abstract class AbstractField { abstract final int declared; }
mixin AbstractFieldMixin on Object { abstract final int fromMixin; }
class Concrete extends AbstractField with AbstractFieldMixin {
  @override
  final int declared = 1;
  @override
  final int fromMixin = 2;
}

class FieldBase { final int shadowed = 0; }
class GetterMiddle extends FieldBase {
  @override
  int get shadowed => 1;
}
class ShadowedByGetter extends GetterMiddle {
  @override
  final int shadowed = 2;
}

Configure overridden-fields

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "suspicious": {
        "overridden-fields": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/suspicious/overridden-fields: <reason>