Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Add a rule prefer_guard_clause for reversing nested if statements#154

Merged
illia-romanenko merged 12 commits into
solid-software:mastersolid-software/solid_lints:masterfrom
velvitoff:use_reverse_if_to_reduce_nestingCopy head branch name to clipboard
Apr 22, 2024
Merged

Add a rule prefer_guard_clause for reversing nested if statements#154
illia-romanenko merged 12 commits into
solid-software:mastersolid-software/solid_lints:masterfrom
velvitoff:use_reverse_if_to_reduce_nestingCopy head branch name to clipboard

Conversation

@velvitoff

Copy link
Copy Markdown
Contributor

No description provided.

@yurii-prykhodko-solid yurii-prykhodko-solid left a comment

Copy link
Copy Markdown
Collaborator

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:

  1. when if block is spanning the entire function body:
void fn() {
  if (true) {
  ...
  }
}
// ->>
void fn() {
  if (false) return;
  ...
}
  1. when if-else is spanning the entire function body

Comment thread lib/src/lints/prefer_guard_clause/prefer_guard_clause_rule.dart Outdated
Comment thread lint_test/prefer_guard_clause_test.dart Outdated
Comment thread lib/src/lints/prefer_guard_clause/visitors/prefer_guard_clause_visitor.dart Outdated

@yurii-prykhodko-solid yurii-prykhodko-solid left a comment

Copy link
Copy Markdown
Collaborator

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.

Comment thread lib/src/lints/reverse_if_to_reduce_nesting/reverse_if_to_reduce_nesting_rule.dart Outdated
Comment thread lib/src/lints/reverse_if_to_reduce_nesting/reverse_if_to_reduce_nesting_rule.dart Outdated
Comment thread lib/src/lints/reverse_if_to_reduce_nesting/reverse_if_to_reduce_nesting_rule.dart Outdated
Comment thread lib/src/lints/reverse_if_to_reduce_nesting/visitors/if_statement_visitor.dart Outdated

@yurii-prykhodko-solid yurii-prykhodko-solid left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Comment thread lib/src/lints/prefer_early_return/visitors/prefer_early_return_visitor.dart Outdated
Comment thread lib/src/lints/prefer_early_return/visitors/prefer_early_return_visitor.dart Outdated
Comment thread lint_test/prefer_early_return_test.dart

@illia-romanenko illia-romanenko left a comment

Copy link
Copy Markdown
Collaborator

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.

@illia-romanenko illia-romanenko merged commit 4ea6cb4 into solid-software:master Apr 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.