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 plus HashAlignment breaks the page #8347

Closed
dorner opened this issue Jul 15, 2020 · 1 comment
Closed

HashSyntax plus HashAlignment breaks the page #8347

dorner opened this issue Jul 15, 2020 · 1 comment
Labels
bug

Comments

@dorner
Copy link

@dorner dorner commented Jul 15, 2020

When mixing Style/HashSyntax with a setting of hash_rockets and the default Layout/HashAlignment cop, auto-correction can break the page and render a syntax error.

Expected behavior

Original code:

some_method(a: 'abc', b: 'abc',
        c: 'abc', d: 'abc'
        )

Expected output:

some_method(:a => 'abc', :b => 'abc',
            :c => 'abc', :d => 'abc'
        )
  end

Actual behavior

Actual output:

some_method(:a => 'abc', :b => 'abc',
        :    c => 'abc', :d => 'abc'
        )

Steps to reproduce the problem

Running rubocop -a on the above code will replicate the problem.

RuboCop version

0.88.0 (using Parser 2.7.1.4, rubocop-ast 0.1.0, running on ruby 2.7.0 x86_64-darwin16)
@koic koic added the bug label Jul 15, 2020
@dorner
Copy link
Author

@dorner dorner commented Jul 15, 2020

So it looks like the problem is that both cops do inserts - HashSyntax inserts the : before the key, and HashAlignment inserts spaces before the key. It looks like these aren't considered clobbers for some reason.

An easy fix would be to reorder the cops so HashSyntax always gets run after HashAlignment. Probably doesn't address the root cause though.

koic added a commit to koic/rubocop that referenced this issue Jul 16, 2020
…ntax`

Fixes rubocop-hq#8347.

This PR fixes an incorrect auto-correct for `EnforcedStyle: hash_rockets` of
`Style/HashSyntax` with `Layout/HashAlignment`.
koic added a commit to koic/rubocop that referenced this issue Jul 16, 2020
…ntax`

Fixes rubocop-hq#8347.

This PR fixes an incorrect auto-correct for `EnforcedStyle: hash_rockets` of
`Style/HashSyntax` with `Layout/HashAlignment`.
dorner added a commit to wishabi/rubocop that referenced this issue Jul 16, 2020
Combining an autocorrect with HashAlignment with one turning hashes into `hash_rocket` syntax would leave the code in a syntax error.
dorner added a commit to wishabi/rubocop that referenced this issue Jul 16, 2020
dorner added a commit to wishabi/rubocop that referenced this issue Jul 16, 2020
bbatsov added a commit that referenced this issue Jul 18, 2020
Fixes #8347.

This PR fixes an incorrect auto-correct for `EnforcedStyle: hash_rockets` of
`Style/HashSyntax` with `Layout/HashAlignment`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

2 participants
You can’t perform that action at this time.