prefer-type-over-var
- Group
- Style
- Path
lint/style/prefer-type-over-var- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 413 of 512
Prefer explicit types over var in ordinary variable declarations.
Checks local, field and top-level var declarations, regardless of initializer.
Explicit types, final and const declarations are not checked. Destructuring
patterns and implicit for-in binding forms are excluded.
Invalid
int readCount() => 3;
var top = readCount();
class Box {
var count = readCount();
}
void main() {
var count = readCount();
var first = readCount(), second = readCount();
var number = 3;
var values = <int>[];
var unset;
}int readCount() => 3;var top = readCount();class Box { var count = readCount();void main() { var count = readCount(); var count = readCount(); var first = readCount(), second = readCount(); var count = readCount(); var first = readCount(), second = readCount(); var first = readCount(), second = readCount(); var number = 3; var number = 3; var values = <int>[]; var values = <int>[]; var unset;Valid
int readCount() => 3;
const topConstant = 3;
final topFinal = readCount();
class Box {
Box();
Box.named();
final field = 3;
static const constant = 3;
int typedField = 3;
}
void main() {
int number = 3;
String text = 'hello';
List<int> items = <int>[];
Box box = Box();
Box other = Box.named();
Box explicitNew = new Box();
dynamic unset;
final finalValue = readCount();
const constantValue = 3;
int typed = readCount();
}Configure prefer-type-over-var
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"prefer-type-over-var": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/prefer-type-over-var: <reason>More style rules
- prefer-typing-uninitialized-variables
prefer_typing_uninitialized_variablesrecommendedFlags uninitialized variables declared without a type annotation.
- 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.