Skip to content

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

Open
@andyw8

Description

@andyw8

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions