Contents

deprecated_member_use_from_same_package

Contents

Avoid using deprecated elements from within the package in which they are declared.

This rule is available as of Dart 3.0.

This rule has a quick fix available.

Details

#

Elements that are annotated with @Deprecated should not be referenced from within the package in which they are declared.

AVOID using deprecated elements.

...

BAD:

dart
// Declared in one library:
class Foo {
  @Deprecated("Use 'm2' instead")
  void m1() {}

  void m2({
      @Deprecated('This is an old parameter') int? p,
  })
}

@Deprecated('Do not use')
int x = 0;

// In the same or another library, but within the same package:
void m(Foo foo) {
  foo.m1();
  foo.m2(p: 7);
  x = 1;
}

Deprecated elements can be used from within other deprecated elements, in order to allow for the deprecation of a collection of APIs together as one unit.

GOOD:

dart
// Declared in one library:
class Foo {
  @Deprecated("Use 'm2' instead")
  void m1() {}

  void m2({
      @Deprecated('This is an old parameter') int? p,
  })
}

@Deprecated('Do not use')
int x = 0;

// In the same or another library, but within the same package:
@Deprecated('Do not use')
void m(Foo foo) {
  foo.m1();
  foo.m2(p: 7);
  x = 1;
}

Usage

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - deprecated_member_use_from_same_package