-
Notifications
You must be signed in to change notification settings - Fork 18
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
Add a rule prefer_guard_clause
for reversing nested if statements
#154
Add a rule prefer_guard_clause
for reversing nested if statements
#154
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The idea seems to mostly work, but I think we lack a clear definition of what we're trying to do here.
I'd look to these cases:
- when
if
block is spanning the entire function body:
void fn() {
if (true) {
...
}
}
// ->>
void fn() {
if (false) return;
...
}
- when
if-else
is spanning the entire function body
lib/src/lints/prefer_guard_clause/prefer_guard_clause_rule.dart
Outdated
Show resolved
Hide resolved
lib/src/lints/prefer_guard_clause/visitors/prefer_guard_clause_visitor.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks like a great start for this lint!
We can expand on it in next iterations.
For now, just need to fixup a few minor issues, and clarify a few pieces.
lib/src/lints/reverse_if_to_reduce_nesting/reverse_if_to_reduce_nesting_rule.dart
Outdated
Show resolved
Hide resolved
lib/src/lints/reverse_if_to_reduce_nesting/reverse_if_to_reduce_nesting_rule.dart
Outdated
Show resolved
Hide resolved
lib/src/lints/reverse_if_to_reduce_nesting/reverse_if_to_reduce_nesting_rule.dart
Outdated
Show resolved
Hide resolved
lib/src/lints/reverse_if_to_reduce_nesting/visitors/if_statement_visitor.dart
Outdated
Show resolved
Hide resolved
lib/src/lints/reverse_if_to_reduce_nesting/visitors/reverse_if_to_reduce_nesting_visitor.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
lib/src/lints/prefer_early_return/visitors/prefer_early_return_visitor.dart
Outdated
Show resolved
Hide resolved
lib/src/lints/prefer_early_return/visitors/prefer_early_return_visitor.dart
Outdated
Show resolved
Hide resolved
lib/src/lints/prefer_early_return/visitors/prefer_early_return_visitor.dart
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - but missing changelog, I'll add it myself.
No description provided.