rubocop-thread_safety
rubocop-thread_safety copied to clipboard
False positive: ivar in Structs
Hi,
In the following example (scaled down from real code), InstanceVariableInClassMethod's diagnostic is wrong.
$ cat struct.rb
class Foo
def self.new_struct
Struct.new(:foo) {
def bar
@bar ||= 42
end
}.new
end
end
s = Foo.new_struct
puts s.bar
$ bundle exec rubocop struct.rb
Inspecting 1 file
C
Offenses:
struct.rb:5:9: C: ThreadSafety/InstanceVariableInClassMethod: Avoid instance variables in class methods.
@bar ||= 42
^^^^
1 file inspected, 1 offense detected
This is version 0.4.4.
PS/ Where is the rendered documentation? I meant, there is https://docs.rubocop.org/rubocop-rails/cops_rails.html for instance, but I could not find anything comparable for Thread Safety.
Hi! Thanks for the bug report.
How would you feel about opening a pull request to start resolving this? I'm happy to support you through it.
I would start by making a new failing test case using your example code.
Thanks!