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

New cop: Every AR find must either be in a conditional or be a bang #333

Open
andyw8 opened this issue Dec 6, 2019 · 1 comment
Open

Comments

@andyw8
Copy link
Contributor

andyw8 commented Dec 6, 2019

This was an idea from @avdi:

https://twitter.com/avdi/status/1202702640397856768?ref_src=twsrc%5Etfw

Idea for a Rails linting rule: every AR find must either be in a conditional or be a bang

Either:

widget = Widget.find_by! color: "green"

Or

if(widget = Widget.find_by color: "green")
# ...

There's no reason to ever leave the discovery of a nil for later. Is there?

There's some interesting discussion in the replies.

It's similar to the existing SaveBang rule.

@pocke pocke mentioned this issue Jan 4, 2020
20 tasks
@koic
Copy link
Member

koic commented Apr 4, 2023

I wonder if this can be generalized to Rails style guide coding rule before creating a new cop. I will transfer this issue to the style guide repo.

@koic koic transferred this issue from rubocop/rubocop-rails Apr 4, 2023
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

No branches or pull requests

2 participants