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

Disallow instance variables in ActiveSupport::Concern#class_methods #14

Merged
merged 2 commits into from
Jul 21, 2022

Conversation

ytjmt
Copy link

@ytjmt ytjmt commented Jul 18, 2022

Closes #5

Methods defined in ActiveSupport::Concern#class_methods blocks are used as class methods.
I added a rule to disallow instance variables in class_methods blocks.

module Example
  extend ActiveSupport::Concern

  class_methods do
    def test(params)
      @params = params
      ^^^^^^^ Avoid instance variables in class methods.
    end
  end
end

Cases using module ClassMethods can already be detected. ( covermymeds#31 )

module Example
  extend ActiveSupport::Concern

  module ClassMethods do
    def test(params)
      @params = params
      ^^^^^^^ Avoid instance variables in class methods.
    end
  end
end

Copy link
Collaborator

@mikegee mikegee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@mikegee mikegee merged commit 2d4a0b0 into rubocop:master Jul 21, 2022
@ytjmt ytjmt deleted the disallow_ivar_in_class_methods_dsl branch July 25, 2022 14:41
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

Successfully merging this pull request may close these issues.

Support detecting offenders in ActiveSupport::Concern#class_methods blocks
2 participants