avoid-unnecessary-overrides-in-state
- Group
- Style
- Path
lint/style/avoid-unnecessary-overrides-in-state- Default
- Off, opt in
- Origin
- Falcon
- Domain
- flutter
- Rule
- 169 of 512
Redundant Flutter State overrides that drop inherited @protected.
Shares the general override rule's forwarding, signature, documentation and
comment checks, but handles only the protected-annotation mismatch that rule
deliberately preserves. All other redundant overrides remain owned by
unnecessary-overrides, so enabling both rules does not duplicate diagnostics.
The enclosing type must resolve to a subtype of Flutter's State declaration.
Invalid
import 'package:flutter/material.dart';
class Redundant extends State<StatefulWidget> {
@override
void initState() => super.initState();
@override
void dispose() { super.dispose(); }
@override
void didChangeDependencies() => super.didChangeDependencies();
@override
void deactivate() => super.deactivate();
@override
void reassemble() => super.reassemble();
} @override void initState() => super.initState(); @override void dispose() { super.dispose(); } @override void didChangeDependencies() => super.didChangeDependencies(); @override void deactivate() => super.deactivate(); @override void reassemble() => super.reassemble();Valid
import 'package:flutter/material.dart';
import 'package:meta/meta.dart';
class Meaningful extends State<StatefulWidget> {
@override
void initState() {
// Initialization will be added here intentionally.
super.initState();
}
@override
void dispose() { print('cleanup'); super.dispose(); }
/// Preserve this lifecycle documentation.
@override
void didChangeDependencies() => super.didChangeDependencies();
@override
void deactivate() {}
@deprecated
@override
void reassemble() => super.reassemble();
}
class Parent {
void dispose() {}
}
class NotState extends Parent {
@override
void dispose() => super.dispose();
}
class StateBase extends State<StatefulWidget> {
void ordinary() {}
}
class OrdinaryState extends StateBase {
// Owned by unnecessary-overrides, not this rule: no protected mismatch.
@override
void ordinary() => super.ordinary();
}
class ProtectedState extends State<StatefulWidget> {
// Keeping protected is also owned by unnecessary-overrides.
@protected
@override
void initState() => super.initState();
}Configure avoid-unnecessary-overrides-in-state
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-unnecessary-overrides-in-state": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-unnecessary-overrides-in-state: <reason>More style rules
- avoid-unnecessary-reassignment
Reports an eager local initializer immediately overwritten without a read.
- avoid-unnecessary-return
Flags bare returns at the end of a function or its final if/block branches.
- avoid-unnecessary-super
Omit implicit
super()initializers and provably redundant member prefixes. - avoid-unused-constructor-parameters
avoid_unused_constructor_parametersFlags constructor parameters that are never used.
- avoid-void-async
avoid_void_asyncrecommendedAvoid
asyncfunctions and methods declared to returnvoid. - avoid-wrapping-in-paddingflutter
Flags Padding directly wrapping a Flutter Container that can own the padding.
- binary-expression-operand-order
binary-expression-operand-orderFlags comparison expressions with a literal on the left-hand side.
- boolean-prefixes
boolean_prefixesFlags boolean identifiers that lack a conventional interrogative prefix.