avoid-assigning-to-static-field
- Group
- Correctness
- Path
lint/correctness/avoid-assigning-to-static-field- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 15 of 512
Flags instance methods writing resolved static fields, including compound assignments and increments. Static methods, top-level functions, declarations, instance fields, setters, and shadowed names are excluded.
Invalid
class Counter {
static int count = 0;
static int? cached;
void update() {
count = 1;
count += 2;
count++;
--count;
cached ??= 1;
Counter.count = 2;
Counter.count *= 2;
Counter.count--;
}
} void update() { count = 1; count = 1; count += 2; count += 2; count++; count++; --count; --count; cached ??= 1; cached ??= 1; Counter.count = 2; Counter.count = 2; Counter.count *= 2; Counter.count *= 2; Counter.count--;Valid
class Counter {
static int count = 0;
int value = 0;
static set setting(int value) {}
void change(int count) {
count = 1;
value = 2;
value++;
this.value += 2;
}
void local() {
int count = 0;
count++;
}
static void reset() {
count = 0;
Counter.count += 1;
count++;
}
}
void change(Counter counter) {
counter.value = 3;
Counter.setting = 1;
final read = Counter.count;
Counter.count = 2;
Counter.count--;
}Configure avoid-assigning-to-static-field
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-assigning-to-static-field": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-assigning-to-static-field: <reason>More correctness rules
- avoid-calling-notifier-members-inside-buildrecommendedriverpod
Flags calls to Riverpod notifier methods during widget build.
- avoid-collection-equality-checksrecommended
Flags equality comparisons between non-constant SDK collections.
- avoid-conditional-hooksrecommendedflutter_hooks
Flags hook calls in conditional branches, short-circuit operands, and loops.
- avoid-constant-assert-conditions
Flags assertions whose Boolean condition is statically constant.
- avoid-constant-conditions
Flags statically constant binary branch, loop, collection, and expression conditions.
- avoid-constant-switches
Flags switch statements and expressions with a statically constant subject.
- avoid-contradictory-expressionsrecommended
Flags pairs of conditions that are always false with
&&or true with||. - avoid-disposing-late-fieldsflutter
Avoid releasing late State fields that may be unset or initialized only by cleanup.