avoid-mutable-global-variables
Same as avoid_mutable_global_variables in Pyramid Lint
- Group
- Correctness
- Path
lint/correctness/avoid-mutable-global-variables- Default
- Off, opt in
- Origin
- Pyramid Lint
- Rule
- 94 of 512
Disallow mutable top-level variables.
Flags a top-level variable that is neither const nor final. A mutable
global can be reassigned from anywhere in the program, so its value at any
moment depends on execution order that no local reading of the code reveals —
a recurring source of subtle bugs and flaky, order-dependent tests. Declare
it const or final; when a value genuinely must change over time, hold it
in an object with a clear owner rather than a free-floating global.
Invalid
/// Mutable top-level variable
var items = <String>[];
/// Mutable int at top-level
int count = 0;
/// Mutable list at top-level
List<int> numbers = [1, 2, 3];
/// Mutable map at top-level
Map<String, String> config = {'key': 'value'};
/// Late top-level variable that is neither final nor const
late String sharedState;
class MyClass {
void example() {
print(items);
}
}/// Mutable top-level variablevar items = <String>[];/// Mutable int at top-levelint count = 0;/// Mutable list at top-levelList<int> numbers = [1, 2, 3];/// Mutable map at top-levelMap<String, String> config = {'key': 'value'};/// Late top-level variable that is neither final nor constlate String sharedState;Valid
/// A final top-level variable is not flagged (only const/final skips).
final RegExp kPattern = RegExp(r'[a-z]+');
/// A final top-level list initialised from a call is still final, so allowed.
final List<int> kComputed = List<int>.generate(3, (i) => i);
/// Const top-level variable
const List<String> kItems = <String>[];
/// Const int at top-level
const int kCount = 0;
/// Const regex pattern
const String kPatternString = r'[a-z]+';
/// Const list at top-level
const List<int> kNumbers = [1, 2, 3];
/// Const map at top-level
const Map<String, String> kConfig = {'key': 'value'};
/// Const string
const String kSharedState = '';
/// Class with mutable state
class MyClass {
/// Instance fields can be mutable
late String instanceState;
/// Private instance field
final List<String> _items = [];
/// Const field in class (no instance state)
static const String kClassName = 'MyClass';
void example() {
print(kItems);
}
}Configure avoid-mutable-global-variables
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-mutable-global-variables": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-mutable-global-variables: <reason>More correctness rules
- avoid-nested-futures
Avoid
Future<Future<T>>,FutureOr<Future<T>>, and other directly nested future wrappers. - avoid-nested-streams-and-futures
Avoid directly nesting SDK streams and futures:
Stream<Future<T>>andFuture<Stream<T>>complicate consumption. - avoid-read-inside-buildrecommendedprovider
Flags non-listening Provider reads directly inside Flutter widget builds.
- avoid-recursive-calls
Reports direct self-calls in functions and methods, including guarded recursion.
- avoid-recursive-widget-callsrecommendedflutter
Warns when a widget's build method constructs the same widget again.
- avoid-ref-inside-state-disposeriverpod
Rejects Riverpod widget references used during State.dispose.
- avoid-ref-read-inside-buildrecommendedriverpod
Flags one-time Riverpod reads of provider state during widget build.
- avoid-ref-watch-outside-buildrecommendedriverpod
Flags Riverpod WidgetRef.watch subscriptions outside synchronous widget build bodies.