avoid-multiple-declarations-per-line
Same as avoid_multiple_declarations_per_line in Dart lints
- Group
- Style
- Path
lint/style/avoid-multiple-declarations-per-line- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 92 of 512
Flags a variable declaration that declares more than one variable.
Declaring each variable on its own line makes each one easier to find, document, and change. Top-level variables, fields, and local variables are checked; the second declared name is reported:
var a = 1, b = 2; // `b` flagged
int x, y; // `y` flagged
for (var i = 0, j = 1; ;) {} // fine: loop initializers are exempt
Invalid
var a = 1, b = 2;
int x = 0, y = 0, z = 0;
class C {
final int p = 1, q = 2;
static String? s, t;
}
void f() {
var i = 0, j = 1;
late final String first,
second;
first = 'a';
second = 'b';
print('$i $j $first $second');
}var a = 1, b = 2; int x = 0, y = 0, z = 0;class C { final int p = 1, q = 2; final int p = 1, q = 2; static String? s, t;void f() { var i = 0, j = 1; late final String first, second;Valid
var a = 1;
var b = 2;
class C {
final int p = 1;
final int q = 2;
}
void f() {
var i = 0;
var j = 1;
// Loop initializers may declare several variables.
for (var k = 0, l = 10; k < l; k++, l--) {
print('$i $j $k $l');
}
final (x, y) = (1, 2);
print('$x $y');
}Configure avoid-multiple-declarations-per-line
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-multiple-declarations-per-line": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-multiple-declarations-per-line: <reason>More style rules
- avoid-non-null-assertion
avoid-non-null-assertionFlags the null-assertion operator
!except on a resolvedMapindex. - avoid-null-checks-in-equality-operators
avoid_null_checks_in_equality_operatorsrecommendedFlags null checks of the parameter inside a custom
operator ==. - avoid-positional-boolean-parameters
avoid_positional_boolean_parametersFlags a positional
boolparameter in a public signature. - avoid-positional-fields-in-records
avoid_positional_fields_in_recordsFlags positional fields in record types.
- avoid-private-typedef-functions
avoid_private_typedef_functionsFlags a private function typedef that is used at most once.
- avoid-public-notifier-propertiesriverpod
Keeps notifier state behind Riverpod's observable state property.
- avoid-redundant-argument-values
avoid_redundant_argument_valuesFlags arguments that pass exactly the parameter's default value.
- avoid-redundant-else
Flags else branches after an if body that unconditionally returns or throws.