rubocop-thread_safety icon indicating copy to clipboard operation
rubocop-thread_safety copied to clipboard

Support detecting offenders in `ActiveSupport::Concern#class_methods` blocks

Open DanielGilchrist opened this issue 3 years ago • 0 comments

Just recently upgraded to v0.4.2 and I noticed that currently the cop doesn't pick up offenders in class_methods do...end blocks

Cases using module ClassMethods works great

module Personable
  extend ActiveSupport::Concern

  module ClassMethods
    def age
      @age ||= 33 # ThreadSafety/InstanceVariableInClassMethod error will occur here appropriately
    end
  end
end

Rails also allows us to use class_methods to achieve the same thing

module Personable
  extend ActiveSupport::Concern

  class_methods do
    def age
      @age ||= 33 # ThreadSafety/InstanceVariableInClassMethod won't detect this
    end
  end
end

It'd be awesome if we could detect cases inside class_methods blocks as well 🤩

https://api.rubyonrails.org/v6.1.3.2/classes/ActiveSupport/Concern.html#method-i-class_methods

DanielGilchrist avatar Jul 14 '21 09:07 DanielGilchrist