deprecated-member-use-from-same-package

Same as deprecated_member_use_from_same_package in Dart lints

Path
lint/correctness/deprecated-member-use-from-same-package
Default
Off, opt in
Origin
Dart lints
Rule
217 of 512

Reports uses of deprecated declarations from their own package.

Canonical project identities and lexical scopes prove code and documentation references; unknown receivers and ambiguous imports remain silent. Deprecated declarations and libraries form a usage frontier, so their bodies, documentation, and metadata are exempt, including part files of deprecated libraries. Library directive messages use canonical package URIs, and local functions stay within their lexical block, switch case, or unbraced statement body. Deprecation messages are trimmed and punctuated like the analyzer's messages. Membership is cached per source. Cascade diagnostics consume shared semantic traversal callbacks, including receiver inference and indexed-assignment classification. Extension owners honor inferred arguments and bounds; super owners follow concrete mixin constraints before interface contracts. Optional parameter deprecations are checked even when the enclosing member is not deprecated. Explicit construction resolves dotted constructor selectors separately from import prefixes; generic class qualifiers retain their constructor metadata. Constructor aliases resolve to the underlying declaration before constructor and deprecated-parameter metadata is inspected. Compound assignments and increments inspect both accessors, while simple assignments inspect only setters. Local metadata follows binding declaration identities, including loop variables; local function metadata also applies to references before its lexical declaration. Enum constants do not name deprecated constructors; implicit extension operators use the same applicable-extension lookup as ordinary members. Member and parameter selectors borrow names and keep declaration kind, access, and static dispatch distinct; retained metadata owns names only during indexing. Grouped references are visited, but grouped callees do not expose declaration parameter metadata as direct invocations do. Null-shortened receiver chains recover reached declaration types until parentheses, preserving declared nullable members and applicable nullable extensions. Named constructor uses cover their full qualifier; implicit super uses cover the complete constructor declaration that makes the implicit call.

Invalid

example.dartdart
@deprecated
void oldFunction() {}
@Deprecated('Use `newValue`.')
int oldValue = 1;
@Deprecated('Use `NewType`.')
class Legacy {}
class Api {
  Api();
  @deprecated
  Api.old();
  @deprecated
  void oldMethod() {}
}
void use(Api value) {
  oldFunction();
  print(oldValue);
  oldValue = 2;
  Legacy? variable;
  Api.old();
  value.oldMethod();
}

class Properties {
  @deprecated
  int oldField = 0;
  @deprecated
  int get oldGetter => 0;
  @deprecated
  set oldSetter(int value) {}
}
class InheritedProperties extends Properties {}
void propertyUses(InheritedProperties value) {
  print(value.oldField);
  print(value.oldGetter);
}
class GlobalUses {
  void call() {
    oldFunction();
  }
}
/// [oldFunction]
void linkedFunction() {}
/// [Properties.oldGetter]
void linkedGetter() {}
class LinkedProperties extends Properties {
  /// [oldField]
  void linkedMember() {}
}
enum OldChoice {
  @deprecated
  old,
  current;
}
void patternUse(OldChoice value) {
  switch (value) {
    case OldChoice.old:
      break;
    case OldChoice.current:
      break;
  }
}
`oldFunction` is deprecated and shouldn't be used.
14void use(Api value) {
15 oldFunction();
`oldValue` is deprecated and shouldn't be used. Use `newValue`.
15 oldFunction();
16 print(oldValue);
`oldValue` is deprecated and shouldn't be used. Use `newValue`.
16 print(oldValue);
17 oldValue = 2;
`Legacy` is deprecated and shouldn't be used. Use `NewType`.
17 oldValue = 2;
18 Legacy? variable;
`Api.old` is deprecated and shouldn't be used.
18 Legacy? variable;
19 Api.old();
`oldMethod` is deprecated and shouldn't be used.
19 Api.old();
20 value.oldMethod();
`oldField` is deprecated and shouldn't be used.
32void propertyUses(InheritedProperties value) {
33 print(value.oldField);
`oldGetter` is deprecated and shouldn't be used.
33 print(value.oldField);
34 print(value.oldGetter);
`oldFunction` is deprecated and shouldn't be used.
37 void call() {
38 oldFunction();
`oldFunction` is deprecated and shouldn't be used.
40}
41/// [oldFunction]
`oldGetter` is deprecated and shouldn't be used.
42void linkedFunction() {}
43/// [Properties.oldGetter]
`oldField` is deprecated and shouldn't be used.
45class LinkedProperties extends Properties {
46 /// [oldField]
`old` is deprecated and shouldn't be used.
55 switch (value) {
56 case OldChoice.old:

Valid

example.dartdart
@deprecated
void oldFunction() { oldFunction(); }
void shadow(void Function() oldFunction) { oldFunction(); }
void localShadow() { void oldFunction() {} oldFunction(); }
void unknown(dynamic value) { value.oldMethod(); }
void freshFunction() {}
void fresh() { freshFunction(); }
@Deprecated('Use freshFunction')
void exempt() { oldFunction(); }

void requiredNamed({@deprecated required int value}) {}

class RequiredNamedConstructor {
  RequiredNamedConstructor({@Deprecated('Still required') required int value});
}

void requiredNamedUses() {
  requiredNamed(value: 1);
  RequiredNamedConstructor(value: 1);
}

class DocumentationShadow {
  @deprecated
  void oldMethod() {}
  /// [oldMethod] is the parameter, not the deprecated member.
  void accept(void Function() oldMethod) {}
}
/// [oldFunction] is the parameter, not the deprecated top-level declaration.
void documentedParameter(void Function() oldFunction) {}

Configure deprecated-member-use-from-same-package

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

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "deprecated-member-use-from-same-package": "error"
      }
    }
  }
}

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

example.dartdart
// falcon-ignore lint/correctness/deprecated-member-use-from-same-package: <reason>
  • diagnostic-describe-all-propertiesdiagnostic_describe_all_propertiesflutter

    Requires every public property of a Diagnosticable class to be referenced in its debug methods.

  • discarded-futuresdiscarded_futures

    Don't discard Futures returned by calls in synchronous functions.

  • dispose-fieldsrecommendedflutter

    Requires other owned disposable State fields to be released in dispose().

  • dispose-focus-node-and-timerrecommendedflutter

    Requires owned FocusNode and Timer fields to be released in State.dispose().

  • dispose-provided-instancesrecommendedriverpod

    Flags provider-created instances with a dispose method that lack ref.onDispose cleanup.

  • dispose-provider-resourcesrecommendedriverpod

    Flags provider-created resources without autoDispose or ref.onDispose cleanup.

  • dispose-providersrecommendedprovider

    Requires cleanup callbacks for disposable values created by package:provider's Provider.

  • emit-new-bloc-state-instancesrecommendedbloc

    Flags Bloc and Cubit emissions that reuse their current state instance.