Skip to content
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

Merged
merged 12 commits into from
Apr 22, 2024
Merged

Add a rule prefer_guard_clause for reversing nested if statements #154

merged 12 commits into from
Apr 22, 2024

Conversation

velvitoff
Copy link
Contributor

No description provided.

Copy link
Collaborator

@yurii-prykhodko-solid yurii-prykhodko-solid left a 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:

  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

Copy link
Collaborator

@yurii-prykhodko-solid yurii-prykhodko-solid left a 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.

Copy link
Collaborator

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

Choose a reason for hiding this comment

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

LGTM!

Copy link
Collaborator

@illia-romanenko illia-romanenko left a 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.

@illia-romanenko illia-romanenko merged commit 4ea6cb4 into solid-software:master Apr 22, 2024
1 check passed
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