Contents
Contents

Missing deprecated annotation.

This rule is available as of Dart 2.13.0.

Details

#

DO apply @Deprecated() consistently:

  • if a class is deprecated, its constructors should also be deprecated.
  • if a field is deprecated, the constructor parameter pointing to it should also be deprecated.
  • if a constructor parameter pointing to a field is deprecated, the field should also be deprecated.

BAD:

dart
@deprecated
class A {
  A();
}

class B {
  B({this.field});
  @deprecated
  Object field;
}

GOOD:

dart
@deprecated
class A {
  @deprecated
  A();
}

class B {
  B({@deprecated this.field});
  @deprecated
  Object field;
}

class C extends B {
  C({@deprecated super.field});
}

Usage

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - deprecated_consistency