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 wrong offense in Style/SymbolProc #9232

Merged
merged 1 commit into from Dec 16, 2020

Conversation

tdeo
Copy link
Contributor

@tdeo tdeo commented Dec 15, 2020

While upgrading to rubocop 1.6.1, I noticed that the Style/SymbolProc was registering an offense on the following code:

array.map { _2.first }

And suggesting to autocorrect to array.map(&:first), which is incorrect in such case.

I believe this was introduced in #9127

I suggest changing the cop to only register offenses for the _1 numbered block argument.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.

@tdeo tdeo force-pushed the td/fix_wrong_offense_in_symbol_proc branch from f024850 to 66a5aa3 Compare December 15, 2020 08:34
@dvandersluis
Copy link
Member

dvandersluis commented Dec 15, 2020

Thanks for catching this!

https://github.com/rubocop-hq/rubocop/blob/701468b5dfea527d991fba5ebd7b181d6750a1a8/lib/rubocop/cop/style/symbol_proc.rb#L25-L30

You can fix this more simply by changing line 28 to ${(args (arg _)) 1} (ie. match only numblocks with 1 numeric arg). Then the rest of the code doesn't need to be changed.

@tdeo tdeo force-pushed the td/fix_wrong_offense_in_symbol_proc branch from 436a13e to 013154c Compare December 16, 2020 07:28
@tdeo
Copy link
Contributor Author

tdeo commented Dec 16, 2020

You can fix this more simply by changing line 28 to ${(args (arg _)) 1} (ie. match only numblocks with 1 numeric arg). Then the rest of the code doesn't need to be changed.

This is indeed a much better solution, thanks

CHANGELOG.md Outdated
@@ -6,6 +6,7 @@

### Bug fixes

* [#9232](https://github.com/rubocop-hq/rubocop/pull/9232): Fix `Style/SymbolProc` registering wrong offense when using a symbol numbered block argument greater than 1, i.e. `[[1, 2]].map { _2.succ }`. ([@tdeo][])
Copy link
Collaborator

Choose a reason for hiding this comment

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

You misplaced this changelog entry. Now they go under the changelog dir and this file is auto-generated on release.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, read the checklist a bit too fast and assumed it still was the same, I amended the commit

@tdeo tdeo force-pushed the td/fix_wrong_offense_in_symbol_proc branch from 013154c to 8b30828 Compare December 16, 2020 17:01
@marcandre marcandre merged commit 8e81c64 into rubocop:master Dec 16, 2020
@marcandre
Copy link
Contributor

Great, thanks!

@tdeo tdeo deleted the td/fix_wrong_offense_in_symbol_proc branch December 17, 2020 09:53
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

4 participants