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

Auto-correct compressed hash syntax incorrect #5019

Closed
swordfish444 opened this issue Nov 9, 2017 · 4 comments
Closed

Auto-correct compressed hash syntax incorrect #5019

swordfish444 opened this issue Nov 9, 2017 · 4 comments
Labels

Comments

@swordfish444
Copy link

swordfish444 commented Nov 9, 2017

An issue with compressed hash syntax being incorrectly auto-corrected.


Expected behavior

model.save(validate:true)

Actual behavior

model.savevalidate: true

Steps to reproduce the problem

user = User.new
user.save:validate=>true

then run rubocop --auto-correct

RuboCop version

$ rubocop -V
0.51.0 (using Parser 2.4.0.0, running on ruby 2.4.1 x86_64-darwin16)
@swordfish444 swordfish444 changed the title Auto-correct bugs Auto-correct model.save:validate Nov 9, 2017
@pocke pocke added the bug label Nov 9, 2017
@pocke
Copy link
Collaborator

pocke commented Nov 9, 2017

It is a problem of Style/HashSyntax

Minimum reproduce

test.rb

a:b => c
$ rubocop --only Style/HashSyntax -a
$ rubocop --only Style/HashSyntax -a
Inspecting 1 file
E

Offenses:

test.rb:1:2: C: [Corrected] Use the new Ruby 1.9 hash syntax.
a:b => c
 ^^^^^
test.rb:1:3: E: unexpected token tCOLON
(Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
ab: c
  ^

1 file inspected, 2 offenses detected, 1 offense corrected

$ cat test.rb
ab: c

@donjar
Copy link
Contributor

donjar commented Nov 10, 2017

I cannot reproduce.

$ rubocop -a test.rb
Inspecting 1 file
C

Offenses:

test.rb:1:1: C: [Corrected] Missing magic comment # frozen_string_literal: true.
a:b => c
^
test.rb:1:2: C: [Corrected] Put one space between the method name and the first argument.
a:b => c
 
test.rb:1:2: C: [Corrected] Use the new Ruby 1.9 hash syntax.
a:b => c
 ^^^^^
test.rb:2:1: C: [Corrected] Add an empty line after magic comments.
a b: c
^

1 file inspected, 4 offenses detected, 4 offenses corrected

$ cat test.rb
# frozen_string_literal: true

a b: c

@pocke
Copy link
Collaborator

pocke commented Nov 10, 2017

@donjar Can you try --only option?

test.rb:1:2: C: [Corrected] Put one space between the method name and the first argument.

This correction conceals the bug.

@swordfish444 swordfish444 changed the title Auto-correct model.save:validate Auto-correct compressed hash syntax incorrect Nov 10, 2017
@donjar
Copy link
Contributor

donjar commented Nov 11, 2017

Oops, didn't notice that. Yeah now it errors.

$ rubocop -a --only Style/HashSyntax test.rb
Inspecting 1 file
E

Offenses:

test.rb:1:2: C: [Corrected] Use the new Ruby 1.9 hash syntax.
a:b => c
 ^^^^^
test.rb:1:3: E: unexpected token tCOLON
(Using Ruby 2.1 parser; configure using TargetRubyVersion parameter, under AllCops)
ab: c
  ^

1 file inspected, 2 offenses detected, 1 offense corrected

$ cat test.rb
ab: c

I'll try a fix. :)

donjar added a commit to donjar/rubocop that referenced this issue Nov 11, 2017
donjar added a commit to donjar/rubocop that referenced this issue Nov 11, 2017
Drenmi added a commit to Drenmi/rubocop that referenced this issue Nov 11, 2017
…ash is used as unspaced argument

This cop's' auto-correct would result in invalid syntax when hash rocket
hashes are used as unspaced arguments. This change fixes that.
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

3 participants