Repository navigation
Add a rule prefer_guard_clause for reversing nested if statements
#154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
illia-romanenko
merged 12 commits into
solid-software:master
from
velvitoff:use_reverse_if_to_reduce_nesting
Apr 22, 2024
Merged
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
7706d89
reverse_if_to_avoid_nesting wip
velvitoff 2de0d3f
change name to prefer_guard_close and improve tests
velvitoff 44dbe63
prefer_guard_clause wip
velvitoff af5a75b
fix test name for prefer_guard_clause
velvitoff c1e4ef8
changed to detecting nested if statements
velvitoff 96008f3
fix pr comments
velvitoff c8fec9f
adapt to two sequential if statements
velvitoff 77579a8
remove (.length <= 2) limit
velvitoff d5acf40
fix alphabetic ordering of imports
velvitoff ebb354c
refactor and fix prefer_early_return_visitor.dart to handle nested if…
4akloon 17ebe00
refactor prefer_early_return
4akloon b09bd81
Merge branch 'master' into use_reverse_if_to_reduce_nesting
4akloon File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
adapt to two sequential if statements
- Loading branch information
commit c8fec9fdccb0efd025f704837cf484218f8bf0ce
There are no files selected for viewing
16 changes: 0 additions & 16 deletions
16
lib/src/lints/prefer_early_return/visitors/if_statement_visitor.dart
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
lib/src/lints/prefer_early_return/visitors/return_statement_visitor.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import 'package:analyzer/dart/ast/ast.dart'; | ||
| import 'package:analyzer/dart/ast/visitor.dart'; | ||
|
|
||
| /// The AST visitor that will collect every Return statement | ||
| class ReturnStatementVisitor extends RecursiveAstVisitor<void> { | ||
| final _nodes = <ReturnStatement>[]; | ||
|
|
||
| /// All unnecessary return statements | ||
| Iterable<ReturnStatement> get nodes => _nodes; | ||
|
|
||
| @override | ||
| void visitReturnStatement(ReturnStatement node) { | ||
| super.visitReturnStatement(node); | ||
| _nodes.add(node); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.