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

Idea for extension of GuardClause cop #2476

Closed
madwort opened this issue Dec 5, 2015 · 2 comments
Closed

Idea for extension of GuardClause cop #2476

madwort opened this issue Dec 5, 2015 · 2 comments

Comments

@madwort
Copy link
Contributor

madwort commented Dec 5, 2015

I'm tidying up an old codebase, and have seen some instances of this pattern:

if good_data
  ..do stuff..
else
  fail "bad data"
end

which I think would be nicer as:

fail "bad data" unless good_data

...do stuff...

but I don't think the Style/GuardClause cop currently catches this. There are cases where this is appropriate, though, for example case or chained elsifs :

case type_of_data
when data_type1
  ..do stuff 1..
when data_type2
  ..do stuff 2..
else
  fail "bad data"
end

Does this warrant a feature request? (I'm currently on 0.35.1 (using Parser 2.2.3.0, running on ruby 2.2.2 x86_64-linux))

@jonas054
Copy link
Collaborator

I agree that this would be a good idea. Putting it in the existing Style/GuardClause seems reasonable.

@alexdowad
Copy link
Contributor

Just pushing a commit which fixes this one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants