deprecated_consistency
Missing deprecated annotation.
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});
}
Enable
#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
If you're instead using the YAML map syntax to configure linter rules, add deprecated_consistency: true
under linter > rules:
analysis_options.yaml
yaml
linter:
rules:
deprecated_consistency: true
Was this page's content helpful?
Thank you for your feedback!
Provide details Thank you for your feedback! Please let us know what we can do to improve.
Provide details Unless stated otherwise, the documentation on this site reflects Dart 3.8.1. Page last updated on 2025-03-07. View source or report an issue.