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

[Fix #8347] Fix an incorrect auto-correct for Style/HashSyntax #8351

Conversation

koic
Copy link
Member

@koic koic commented Jul 16, 2020

Fixes #8347.

This PR fixes an incorrect auto-correct for EnforcedStyle: hash_rockets of Style/HashSyntax with Layout/HashAlignment.


Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

Fixes rubocop#8347.

This PR fixes an incorrect auto-correct for `EnforcedStyle: hash_rockets` of
`Style/HashSyntax` with `Layout/HashAlignment`.
)
RUBY
end

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing - I just spent about four hours trying to get this to work via way overcomplicating the expect_correction method (basically by adding a let(:run_first) variable). This is a million times cleaner. :) Going to miss having a PR to Rubocop but I guess I'll have other opportunities!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm curious: what was the difficulty with expect_correction? This test with the CLI is much slower...

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The issue is that you can only run one cop at a time. There's no easy way to pass it multiple cops to run one after another. This bug only happens when one cop makes a change and the next one makes a second change - the two insertions end up in an invalid state.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was under the impression that let(:other_cops) { { 'Other/Cop' => ... } } was the way to go, but indeed looks like it's not the case. I opened #8352 as it should be easily doable to specify additional cops.

@bbatsov bbatsov merged commit 0117efb into rubocop:master Jul 18, 2020
@bbatsov
Copy link
Collaborator

bbatsov commented Jul 18, 2020

Thanks!

@koic koic deleted the fix_an_incorrect_autocorrect_for_style_hash_syntax branch July 18, 2020 07:09
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

Successfully merging this pull request may close these issues.

HashSyntax plus HashAlignment breaks the page
4 participants