proper-super-init-state
Same as proper_super_init_state in Pyramid Lint
- Group
- Correctness
- Path
lint/correctness/proper-super-init-state- Default
- On (recommended)
- Origin
- Pyramid Lint
- Domain
- flutter
- Rule
- 425 of 512
Require super.initState() to be the first statement of a resolved Flutter
State subclass's initState override.
Invalid
import 'package:flutter/material.dart';
class A extends State<StatefulWidget> {
@override
void initState() {
doStuff();
super.initState();
}
}
class B extends State<StatefulWidget> {
int x = 0;
@override
void initState() {
x = 1;
}
}
class C extends State<StatefulWidget> {
@override
void initState() {}
}
class D extends ConsumerState<StatefulWidget> {
@override
void initState() {
final a = 1;
super.initState();
print(a);
}
}
class E extends State<StatefulWidget> {
@override
void initState() {
setup();
super.initState();
}
} doStuff(); super.initState(); @override void initState() { @override void initState() {} setup(); super.initState();Valid
import 'package:flutter/material.dart';
class A extends State<StatefulWidget> {
@override
void initState() {
super.initState();
doStuff();
}
}
class B extends State<StatefulWidget> {
@override
void initState() {
super.initState();
}
}
class C extends ConsumerState<StatefulWidget> {
@override
void initState() {
super.initState();
final a = 1;
print(a);
}
}
class D {
void initState() {
doStuff();
}
}
class E extends StatelessWidget {
void initState() {}
}Configure proper-super-init-state
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"proper-super-init-state": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/proper-super-init-state: <reason>More correctness rules
- require-super-disposerecommendedflutter
Require
super.dispose()in Flutter State dispose overrides. - sort-pub-dependencies
sort_pub_dependenciescross-fileRequire
pubspec.yamldependency sections to be sorted alphabetically. - test-types-in-equals
test_types_in_equalsrecommendedFlags casting the parameter of
operator ==instead of testing its type. - throw-in-finally
throw_in_finallyrecommendedFlags
throwinside afinallyblock. - type-literal-in-constant-pattern
type_literal_in_constant_patternrecommendedDon't use constant patterns whose expressions have the core
Typetype. - undeclared-dependenciescross-file
Report package imports and exports missing from the enclosing pubspec.
- unnecessary-flutter-importsrecommendedflutter
Disallow unused Flutter framework and
dart:asyncimports. - unnecessary-nullable
check-unnecessary-nullablecross-fileFlags private function or method parameters whose nullable type is unnecessary.