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 #4229 Unexpected Style/HashSyntax consistency offence #6428

Merged
merged 4 commits into from Dec 16, 2018
Merged

Fix #4229 Unexpected Style/HashSyntax consistency offence #6428

merged 4 commits into from Dec 16, 2018

Conversation

timon
Copy link
Contributor

@timon timon commented Oct 30, 2018

Caching the value of force_hash_rockets? for autocorrect has a side-effect of flagging an offence every ruby19-style hash pair after the first encounter of hash with symbol value when UseHashRocketsWithSymbolValue is on, so the following code is incorrectly marked as offensive:

  scope :module => :users do
    resources :registrations, only: %i(create update destroy)
  end

I have removed memoization from force_hash_rockets? method and added a test case to check that future optimizations for autocorrect won't break the checks.


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 rake default. It executes all tests and RuboCop for itself, and generates the documentation.

Caching the value of force_hash_rockets? for autocorrect has a side-effect
of flagging an offence every ruby19-style hash pair after the first encounter
of hash with symbol value when UseHashRocketsWithSymbolValue is on.
Copy link
Contributor

@bquorning bquorning left a comment

Choose a reason for hiding this comment

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

When a method takes arguments, those arguments should usually be taken into consideration when memoizing (with e.g. @memo ||= {} ; @memo[input] ||= …)

In this case I think it makes perfect sense to just remove the memoization.

/cc @Drenmi re. #3884.

lib/rubocop/cop/style/hash_syntax.rb Outdated Show resolved Hide resolved
Copy link
Collaborator

@Drenmi Drenmi left a comment

Choose a reason for hiding this comment

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

🚀

@bquorning bquorning merged commit f2ec4a6 into rubocop:master Dec 16, 2018
@bquorning
Copy link
Contributor

@bbatsov I believe I saw you recently mentioning that @rubocop-hq/rubocop-core members should merge more PRs, to get higher throughput on pending pull requests.

I merged this one. Please met me know if I did wrong.

@timon timon deleted the fix/hash-syntax-bad-cache branch May 6, 2019 09:39
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.

None yet

3 participants