Skip to content

Commit

Permalink
remove (.length <= 2) limit
Browse files Browse the repository at this point in the history
  • Loading branch information
velvitoff committed Mar 29, 2024
1 parent c8fec9f commit 77579a8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ class PreferEarlyReturnVisitor extends RecursiveAstVisitor<void> {

if (!(nextStatementIsEmptyReturn || nextStatementIsNull)) return;

// limit to only handling cases with two ifs
if (ifStatements.length > 2) return;

_handleIfStatement(ifStatements.last);
}

Expand Down
25 changes: 25 additions & 0 deletions lint_test/prefer_early_return_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -210,3 +210,28 @@ void twoSeqentialIfSomething2() {
_doSomething();
}
}

void threeSeqentialIfReturn() {
//no lint
if (false) return;
if (true) return;
//expect_lint: prefer_early_return
if (true) {
_doSomething();
}

return;
}

void threeSeqentialIfReturn2() {
//no lint
if (false) return;
//no lint
if (true) {
_doSomething();
}
//expect_lint: prefer_early_return
if (true) {
_doSomething();
}
}

0 comments on commit 77579a8

Please sign in to comment.