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

False positive: ivar in Structs #16

Open
akimd opened this issue Nov 1, 2022 · 1 comment
Open

False positive: ivar in Structs #16

akimd opened this issue Nov 1, 2022 · 1 comment

Comments

@akimd
Copy link

akimd commented Nov 1, 2022

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.

@mikegee
Copy link
Collaborator

mikegee commented Nov 2, 2022

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.

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

No branches or pull requests

2 participants