deprecated-consistency
Same as deprecated_consistency in Dart lints
- Group
- Style
- Path
lint/style/deprecated-consistency- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 216 of 512
Flags deprecations that are not carried through to related declarations.
Deprecating a class implies deprecating its constructors, and a deprecated
field implies that the initializing formal (this.field) that sets it is
deprecated too — and vice versa. Leaving one side unmarked means callers get
no warning on the path they actually use.
@deprecated
class A {
A(); // flagged: constructor not deprecated
}
class B {
B({this.field}); // flagged: parameter not deprecated
@Deprecated('Use x')
Object? field;
}
Private fields are not checked. Deprecation metadata is resolved to
dart:core, including prefixed references and named Deprecated
constructors; user-defined lookalikes do not count.
Primary constructors are checked separately from their enclosing type;
only their own body metadata deprecates them. Header initializing formals
participate in the same field/parameter consistency checks.
Invalid
@deprecated
class A {
A();
}
@Deprecated('Use B2 instead')
class B {
B.named();
@Deprecated('ok')
B();
}
class C {
C({this.field});
@Deprecated('Use x instead')
Object? field;
}
class D {
D({@Deprecated('Use y instead') this.field});
Object? field;
}
class E {
E(this.value, {@deprecated this.legacy});
final int value;
final int? legacy;
}
@deprecated
enum Mode {
on(1),
off(0);
const Mode(this.code);
final int code;
}
@Deprecated.extend()
class Extendable {
Extendable();
}
@Deprecated.implement()
class Implementable {
Implementable();
}
@deprecated
extension type Representation(int value) {
Representation.named(this.value);
}
@deprecated
extension type PrivateRepresentation._(int value) {}
typedef Dep = Deprecated;
@Dep('old')
class Aliased {
Aliased();
}
@Dep.extend()
class AliasedNamed {
AliasedNamed();
}
@deprecated
extension type const ConstRepresentation(int value) {}
@deprecated
extension type const ConstNamedRepresentation._(int value) {}class A { A();class B { B.named();class C { C({this.field}); Object? field; final int value; final int? legacy; const Mode(this.code);class Extendable { Extendable();class Implementable { Implementable();@deprecatedextension type Representation(int value) {extension type Representation(int value) { Representation.named(this.value);@deprecatedextension type PrivateRepresentation._(int value) {}class Aliased { Aliased();class AliasedNamed { AliasedNamed();@deprecatedextension type const ConstRepresentation(int value) {}@deprecatedextension type const ConstNamedRepresentation._(int value) {}Valid
@deprecated
class A {
@deprecated
A();
}
@Deprecated('Use B2 instead')
class B {
@Deprecated('Use B2.named instead')
B.named();
}
class C {
C({@Deprecated('Use x instead') this.field});
@Deprecated('Use x instead')
Object? field;
}
// Neither side deprecated.
class D {
D(this.field);
final Object? field;
}
// Private fields are not part of the public API.
class E {
E(this._secret);
@deprecated
final int _secret;
int get secret => _secret;
}
// A deprecated constructor in a non-deprecated class is fine.
class F {
@Deprecated('Use F.create')
F();
F.create();
}
// Static fields are not initialized by formals.
class G {
@deprecated
static int counter = 0;
G(int counter);
}
@Deprecated.extend()
class ConsistentNamed {
@deprecated
ConsistentNamed();
}
class ConsistentField {
ConsistentField(@deprecated this.value);
@Deprecated('old')
final int value;
}
@Deprecated.new('old')
class ExplicitUnnamed {
@Deprecated.new('old')
ExplicitUnnamed();
}
// Representation fields have no reportable field-fragment name offset.
extension type DeprecatedRepresentationParameter(int value) {
DeprecatedRepresentationParameter.named(@deprecated this.value);
}
typedef Dep = Deprecated;
@Dep('old')
class ConsistentAlias {
@Dep('old')
ConsistentAlias();
}Configure deprecated-consistency
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"deprecated-consistency": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/deprecated-consistency: <reason>More style rules
- directives-ordering
directives_orderingFlags import and export directives that break the Effective Dart ordering.
- do-not-use-environment
do_not_use_environmentDisallow reading compilation environment declarations, including type aliases.
- double-literal-format
double-literal-formatFlags double literals written with redundant or missing digits.
- empty-constructor-bodies
empty_constructor_bodiesrecommendedFlags constructors with an empty block body
{}. - enum-constants-ordering
Flags enum constants whose declared names violate the configured order.
- eol-at-end-of-file
eol_at_end_of_filerecommendedFlags a non-empty file that does not end with exactly one line break.
- extend-equatableequatable
Require Equatable semantics for configured class/file name patterns.
- file-names
file_namesrecommendedEnforces
lowercase_with_underscoresfor source file names.