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

Rails/EnumUniqueness crashes #3918

Closed
savef opened this issue Jan 16, 2017 · 3 comments
Closed

Rails/EnumUniqueness crashes #3918

savef opened this issue Jan 16, 2017 · 3 comments

Comments

@savef
Copy link
Contributor

savef commented Jan 16, 2017

These seem to be related to what #3751 was fixing.

I am getting an error fetching my keys from a method call like so:

enum status: User.statuses.keys
# undefined method `values' for "s(:send,\n  s(:send,\n    s(:const, nil, :User), :statuses), :keys)":RuboCop::AST::Node

Additionally, here's another form using a variable that errors:

var = %w(one two three)
enum status: var
# undefined method `values' for s(:lvar, :var):RuboCop::AST::Node

Whereas enum status: %w(one two three) is fine.


RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.47.0 (using Parser 2.3.3.1, running on ruby 2.3.1 x86_64-linux)
@bquorning
Copy link
Contributor

Fails also if the state value is a hash:

STATES = { foo: 0, bar: 1 }
enum state: STATES

@UksonCode
Copy link

UksonCode commented Jan 16, 2017

And also if the enums are stored in normal array

ROLES = [:boss, :employee].freeze
enum role: ROLES

@Drenmi
Copy link
Collaborator

Drenmi commented Jan 16, 2017

I looked into this, and found the reason this cop was so fragile. The node matcher would match any node type passed as a value to the hash, whereas it's only possible for us to inspect (hash- and array) literals.

I've submitted a fix for this. 😀

Drenmi added a commit to Drenmi/rubocop that referenced this issue Jan 16, 2017
…non-literal hash value

This cop would break on any enum hash that did not have a literal value.
This change fixes that.
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

4 participants