Skip to content

Cop idea: Prefer class_methods do over module ClassMethods #1484

@maxjacobson

Description

@maxjacobson

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

No, this is a request for a new cop.

Describe the solution you'd like

When I write the following code:

module Foo
  extend ActiveSupport::Concern

  module ClassMethods
    def bar
      baz
    end
  end
end

Then rubocop-rails will suggest changing the code to the equivalent:

module Foo
  extend ActiveSupport::Concern

  class_methods do
    def bar
      baz
    end
  end
end

Either works, but for teams which would prefer to consistently use one or the other, it would be nice for rubocop-rails to help provide consistency. This should be configurable to prefer either version.

Describe alternatives you've considered

Happy to continue tolerating the inconsistency

Additional context

N/A

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