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

HashSyntax autocorrect breaks some symbols when targeting 2.2 and up #5313

Closed
mvz opened this issue Dec 26, 2017 · 1 comment
Closed

HashSyntax autocorrect breaks some symbols when targeting 2.2 and up #5313

mvz opened this issue Dec 26, 2017 · 1 comment
Labels

Comments

@mvz
Copy link
Contributor

mvz commented Dec 26, 2017

When targeting Ruby 2.2 and up, HashSyntax' autocorrect can produce invalid results. This happens for symbols like :'&&', for which Ruby 2.2 added support with the new hash syntax.

Expected behavior

With TargetRubyVersion: 2.2 in .rubocop.yml, when running rubocop -a, the following code:

{ :'&&' => :foo }

should be corrected to:

{ '&&': :foo }

Actual behavior

The code is changed to:

{ &&: :foo }

This is syntactically invalid.

Steps to reproduce the problem

Create a file .rubocop.yml with:

AllCops:
  TargetRubyVersion: 2.2

Create a file foo.rb with:

{ :'&&' => :foo }

Run rubocop -a.

RuboCop version

This bug occurs with:

0.52.0 (using Parser 2.4.0.2, running on ruby 2.2.6 x86_64-linux)
0.52.0 (using Parser 2.4.0.2, running on ruby 2.3.6 x86_64-linux)
0.52.0 (using Parser 2.4.0.2, running on ruby 2.4.3 x86_64-linux)
0.52.0 (using Parser 2.4.0.2, running on ruby 2.5.0 x86_64-linux)

This bug does not occur with:

0.50.0 (using Parser 2.4.0.0, running on ruby 2.2.6 x86_64-linux)
0.51.0 (using Parser 2.4.0.2, running on ruby 2.4.3 x86_64-linux)
@mvz
Copy link
Contributor Author

mvz commented Dec 27, 2017

Thanks, @garettarrowood

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants