always-put-control-body-on-new-line
Same as always_put_control_body_on_new_line in Dart lints
- Group
- Style
- Path
lint/style/always-put-control-body-on-new-line- Default
- Off, opt in
- Origin
- Dart lints
- Rule
- 5 of 512
Flags a control-flow body that starts on the same line as its control clause.
Putting the body of an if, else, for, while, or do on the line of
its condition hides it from a reader skimming the left edge of the code. For
a block body, the first statement inside the block is what must move:
if (done) return; // flagged
while (x) { x = next(); } // flagged
if (done) {
return;
} else return; // flagged
if (done) {} // fine: empty block
An else if chain is not reported at its else.
Invalid
void f(bool ok, List<int> xs) {
if (ok) return;
if (ok) { print('same line'); }
if (ok) {
print('then');
} else print('else');
for (var i = 0; i < 3; i++) print(i);
for (final x in xs) print(x);
while (ok) ok = false;
do print('once');
while (false);
do { print('block'); }
while (false);
if (xs case [var first]) print(first);
}void f(bool ok, List<int> xs) { if (ok) return; if (ok) { print('same line'); } print('then'); } else print('else'); for (var i = 0; i < 3; i++) print(i); for (final x in xs) print(x); while (ok) ok = false; do print('once'); do { print('block'); } if (xs case [var first]) print(first);Valid
void f(bool ok, List<int> xs) {
if (ok)
return;
if (ok) {
print('then');
} else if (xs.isEmpty) {
print('else if is not reported at its else');
} else {
print('else');
}
if (ok) {}
for (var i = 0; i < 3; i++)
print(i);
for (final x in xs) {
print(x);
}
while (ok) {
ok = false;
}
do {
print('once');
} while (false);
if (ok) // comment
print('body on the next line');
}Configure always-put-control-body-on-new-line
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"always-put-control-body-on-new-line": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/always-put-control-body-on-new-line: <reason>More style rules
- always-put-required-named-parameters-first
always_put_required_named_parameters_firstFlags a required named parameter declared after an optional named one.
- always-specify-types
always_specify_typesRequires explicit type annotations everywhere a type could be inferred.
- annotate-overrides
annotate_overridesrecommendedRequires
@overrideon members that override an inherited declaration. - arguments-ordering
Named arguments follow their resolved parameter declaration order by default.
- avoid-abbreviations-in-doc-comments
avoid_abbreviations_in_doc_commentsFlags Latin abbreviations in doc comments.
- avoid-annotating-with-dynamic
avoid_annotating_with_dynamicFlags parameters explicitly annotated with
dynamic. - avoid-bloc-public-fieldsbloc
Keep package-confirmed Bloc instance fields private; inherited API overrides are allowed.
- avoid-bloc-public-methodsbloc
Enforce the package-confirmed Bloc convention.