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

Metrics/ClassLength cop failing on multi-variable assignment after 0.90.0 #8880

Closed
boomer196 opened this issue Oct 9, 2020 · 4 comments · Fixed by #8883
Closed

Metrics/ClassLength cop failing on multi-variable assignment after 0.90.0 #8880

boomer196 opened this issue Oct 9, 2020 · 4 comments · Fixed by #8883
Labels

Comments

@boomer196
Copy link

Expected behavior

Metrics/ClassLength cop should be able to examine the file

Actual behavior

An error occurred while Metrics/ClassLength cop was inspecting

undefined method 'class_definition?' for :X:Symbol
undefined method 'class_definition?' for :Y:Symbol

Steps to reproduce the problem

The line of code it was failing on was similar to this:

class Foo
  A = "blah".freeze
  X = Y = Z = [["x", "X"], ["y", "Y"], ["z", "Z"]].freeze
end

I was upgrading from 0.90.0 to 0.93.0 when I found the issue.

RuboCop version

$ [bundle exec] rubocop -V
0.93.0 (using Parser 2.7.2.0, rubocop-ast 0.7.1, running on ruby 2.6.6 x86_64-darwin18)
@natematykiewicz
Copy link

Are you intentionally assigning 3 constants to the same array of arrays? I agree that this should parse, but it also seems like you meant to write:

X, Y, Z = [["x", "X"], ["y", "Y"], ["z", "Z"]].freeze

Example:

A = "blah".freeze
A
=> "blah"


X = Y = Z = [["x", "X"], ["y", "Y"], ["z", "Z"]].freeze
X
=> [["x", "X"], ["y", "Y"], ["z", "Z"]]
Y
=> [["x", "X"], ["y", "Y"], ["z", "Z"]]
Z
=> [["x", "X"], ["y", "Y"], ["z", "Z"]]

I guess I'm also trying to confirm that your code example is accurate to the real-world problem.

koic added a commit to koic/rubocop that referenced this issue Oct 10, 2020
Fixes rubocop#8880.

This PR fixes an error for `Style/ClassLength`
when overlapping constant assignments.
@koic koic added the bug label Oct 10, 2020
@boomer196
Copy link
Author

Yes, it's intentional. I probably should have used a different example. I apologize. Thanks for following up.

This should cause it to fail as well:

A = B = C = "blah".freeze

vs this and the cop can process:

A = "blah".freeze
B = A
C = A

@natematykiewicz
Copy link

natematykiewicz commented Oct 10, 2020

@koic is very fast! #8883

@key88sf
Copy link

key88sf commented Oct 10, 2020

I have the same problem. Thanks for fixing!

bbatsov pushed a commit that referenced this issue Oct 12, 2020
Fixes #8880.

This PR fixes an error for `Style/ClassLength`
when overlapping constant assignments.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants