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

Autocorrect of HashSytnax does not work in some case #919

Closed
iblue opened this issue Mar 25, 2014 · 2 comments
Closed

Autocorrect of HashSytnax does not work in some case #919

iblue opened this issue Mar 25, 2014 · 2 comments
Assignees

Comments

@iblue
Copy link

iblue commented Mar 25, 2014

Given the following file

FactoryGirl.build :user, :email => "[email protected]"
FactoryGirl.build :user, :email=> "[email protected]"

When I run rubocop --only HashSyntax --auto-correct then I get

Inspecting 1 file
C

Offenses:

example.rb:1:26: C: [Corrected] Use the new Ruby 1.9 hash syntax.
FactoryGirl.build :user, :email => "[email protected]"
                         ^^^^^^^^^
example.rb:2:26: C: [Corrected] Use the new Ruby 1.9 hash syntax.
FactoryGirl.build :user, :email=> "[email protected]"
                         ^^^^^^^^

1 file inspected, 2 offenses detected, 2 offenses corrected

But it does not correct :email=> "[email protected]". I found the comment at https://github.com/bbatsov/rubocop/blob/master/lib/rubocop/cop/style/hash_syntax.rb#L41 which says that it does not autocorrect in this cases, but I don't understand why.

@jonas054
Copy link
Collaborator

If HashSyntax and SpaceAroundOperators were to change the code simultaneously, it would lead to destroyed code. The special logic was added in this commit.

But you've exposed a bug. HashSyntax avoids making its correction if it thinks that SpaceAroundOperators is about to make a change. It does this by looking at configuration. It's just that --only doesn't disable all other cops by changing their configuration, so this is not the right way to find out if SpaceAroundOperators is active.

Actually I think there's another way to solve the problem with interference between cops now. There's a loop around auto-correction that picks up exceptions caused by conflicting corrections and tries to do them one by one instead. This will work if we make the correction ranges larger so that they cause "clobbering".

I will try to fix this.

@jonas054 jonas054 self-assigned this Mar 25, 2014
bbatsov added a commit that referenced this issue Mar 27, 2014
[Fix #919] Remove auto-correct avoidance in HashSyntax
@iblue
Copy link
Author

iblue commented Mar 27, 2014

👍 Great! Thank you very much!

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