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

Cop idea: detect use of #find in control flow #907

Closed
Drenmi opened this issue Jan 6, 2023 · 2 comments
Closed

Cop idea: detect use of #find in control flow #907

Drenmi opened this issue Jan 6, 2023 · 2 comments

Comments

@Drenmi
Copy link
Contributor

Drenmi commented Jan 6, 2023

Is your feature request related to a problem? Please describe.

Quite often I see people write code with the assumption that #find will return a falsey result when failing to find a record.

Describe the solution you'd like

Perhaps we can have a cop that detects at least the most basic cases of use of #find in conditionals, e.g.:

if foo = Foo.find(params[:id])
@koic
Copy link
Member

koic commented Jan 15, 2023

This cop should handle if foo = Foo.find_by!(conditions) as well, right?

@koic
Copy link
Member

koic commented Apr 4, 2023

I will close this issue because it can be considered together with rubocop/rails-style-guide#333.

@koic koic closed this as not planned Won't fix, can't repro, duplicate, stale 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