Skip to content

Cop idea: prefer symbol proc to if: and unless: filter lambdas #335

@vlad-pisanov

Description

@vlad-pisanov

Model hooks and controller filters that receive if: and unless: lambdas can be written more succinctly using symbols if the lambda consists of a single method call. This cop would enforce either style consistently based on configuration.

# bad
before_save    :log, if: -> { name_changed? }
around_destroy :baz, if: -> (user) { user.new? }
after_action   :foo, unless: -> { self.bar? }

# good
before_save    :log, if: :name_changed?
around_destroy :baz, if: :new?
after_action   :foo, unless: :bar?

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