prefer-typing-uninitialized-variables
Same as prefer_typing_uninitialized_variables in Dart lints
- Group
- Style
- Path
lint/style/prefer-typing-uninitialized-variables- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 414 of 512
Flags uninitialized variables declared without a type annotation.
When a declaration has no initializer, there is no value for the analyzer to
infer a type from, so var x; leaves the variable as dynamic — silently
opting out of static checking on every later use. Writing int x; instead
documents intent and restores type safety at no cost. The rule fires only on
declarators that are both untyped and uninitialized; a declaration is exempt
as soon as it carries a type annotation. It covers local variables, fields,
and top-level variables.
Invalid
// Uninitialized variables without a type annotation.
var topLevel;
void f() {
var a;
var b;
late var d;
a = 1;
b = 2;
d = 3;
print(a + b + d);
}
class C {
var field;
static var s;
}// Uninitialized variables without a type annotation.var topLevel;void f() { var a; var a; var b; var b; late var d;class C { var field; var field; static var s;Valid
// Either a type annotation or an initializer is present.
int topLevel = 0;
void f() {
int a;
var b = 1;
final c = 2;
String? d;
double e = 0.0;
a = 5;
d = 'x';
print(b + c + e + a + d.length);
}
class C {
int field = 0;
var typed = 'x';
static int s = 1;
}Configure prefer-typing-uninitialized-variables
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-typing-uninitialized-variables": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-typing-uninitialized-variables: <reason>More style rules
- prefer-underscore-for-unused-callback-parameters
prefer_underscore_for_unused_callback_parametersFlags unused closure parameters that are not named with underscores.
- prefer-void-callbackflutter
Prefers Flutter's
VoidCallbackalias over a nongenericvoid Function()type. - provide-deprecation-message
provide_deprecation_messagerecommendedFlags
@deprecatedand@Deprecated()annotations that carry no message. - public-member-api-docs
public_member_api_docsDocuments public declarations and members in package libraries.
- record-fields-ordering
Flags named record type fields that violate the configured order.
- require-trailing-commas
require_trailing_commasFlags a multi-line call, declaration, assert, or collection literal that is missing a trailing comma.
- sized-box-shrink-expand
sized_box_shrink_expandrecommendedflutterPrefers
SizedBox.shrink()/SizedBox.expand()over aSizedBoxsized to zero or infinity. - slash-for-doc-comments
slash_for_doc_commentsrecommendedFlags
/** ...