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 #11732] Make Style/MapToHash and Style/MapToSet aware of symbol proc #11735

Conversation

koic
Copy link
Member

@koic koic commented Mar 24, 2023

Fixes #11732.

This PR makes Style/MapToHash and Style/MapToSet aware of symbol proc.


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.

… of symbol proc

Fixes rubocop#11732.

This PR makes `Style/MapToHash` and `Style/MapToSet` aware of symbol proc.
@bbatsov bbatsov merged commit 5d98bd8 into rubocop:master Mar 25, 2023
@bbatsov
Copy link
Collaborator

bbatsov commented Mar 25, 2023

Nice!

@koic koic deleted the make_style_map_to_hash_and_map_to_set_aware_of_symbol_proc branch March 25, 2023 06:33
koic added a commit to rubocop/rubocop-rails that referenced this pull request Mar 25, 2023
Follow up rubocop/rubocop#11735.

This PR suppresses the following new `Style/MapToSet` offense:

```console
% bundle exec rubocop
(snip)

Offenses:

spec/project_spec.rb:213:94: C: [Correctable] Style/MapToSet: Pass a block to to_set instead of calling map.to_set.
        RuboCop::Cop::Cop.registry.without_department(:Test).without_department(:Test2).cops.map(&:cop_name).to_set
                                                                                             ^^^

279 files inspected, 1 offense detected, 1 offense autocorrectable
```
koic added a commit to rubocop/rubocop-performance that referenced this pull request Mar 25, 2023
Follow up rubocop/rubocop#11735.

This PR suppresses the following new `Style/MapToSet` offense:

```console
% bundle exec rubocop
Inspecting 115 files
............................................................C......................................................

Offenses:

spec/project_spec.rb:211:94: C: [Correctable] Style/MapToSet: Pass a block to to_set instead of calling map.to_set.
        RuboCop::Cop::Cop.registry.without_department(:Test).without_department(:Test2).cops.map(&:cop_name).to_set
                                                                                             ^^^

115 files inspected, 1 offense detected, 1 offense autocorrectable
```
koic added a commit to koic/rubocop that referenced this pull request Mar 26, 2023
I noticed it when working on rubocop#11735.

This PR makes `Style/MapToHash` and `Style/MapToSet` aware of numbered parameters.
koic added a commit to rubocop/rubocop-ast that referenced this pull request Mar 27, 2023
Follow up rubocop/rubocop#11735.

This PR suppresses the following new `Style/MapToSet` offense:

```console
% bundle exec rubocop
(snip)

Offenses:

lib/rubocop/ast/node_pattern/compiler/atom_subcompiler.rb:41:33: C: [Correctable] Style/MapToSet: Pass a block to to_set instead of calling map.to_set.
            set = node.children.map(&:child).to_set.freeze
                                ^^^

163 files inspected, 1 offense detected, 1 offense autocorrectable
```
MarttiCheng added a commit to MarttiCheng/Rubocop-Performance that referenced this pull request Sep 28, 2023
Follow up rubocop/rubocop#11735.

This PR suppresses the following new `Style/MapToSet` offense:

```console
% bundle exec rubocop
Inspecting 115 files
............................................................C......................................................

Offenses:

spec/project_spec.rb:211:94: C: [Correctable] Style/MapToSet: Pass a block to to_set instead of calling map.to_set.
        RuboCop::Cop::Cop.registry.without_department(:Test).without_department(:Test2).cops.map(&:cop_name).to_set
                                                                                             ^^^

115 files inspected, 1 offense detected, 1 offense autocorrectable
```
SerhiiMisiura added a commit to SerhiiMisiura/Rubocop-Performance that referenced this pull request Oct 5, 2023
Follow up rubocop/rubocop#11735.

This PR suppresses the following new `Style/MapToSet` offense:

```console
% bundle exec rubocop
Inspecting 115 files
............................................................C......................................................

Offenses:

spec/project_spec.rb:211:94: C: [Correctable] Style/MapToSet: Pass a block to to_set instead of calling map.to_set.
        RuboCop::Cop::Cop.registry.without_department(:Test).without_department(:Test2).cops.map(&:cop_name).to_set
                                                                                             ^^^

115 files inspected, 1 offense detected, 1 offense autocorrectable
```
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.

Support for pass-blocks in Style/MapToHash and StyleMapToSet
2 participants