KEMBAR78
Add `Style/ArrayIntersectWithSingleElement` cop by r7kamura · Pull Request #14512 · rubocop/rubocop · GitHub
Skip to content

Conversation

r7kamura
Copy link
Contributor

@r7kamura r7kamura commented Sep 8, 2025

With the addition of the Style/ArrayIntersect cop for Array#intersect? (introduced in Ruby 3.1), applying autocorrection can leave behind awkward code such as intersect?([element]).

This expression is equivalent to include?(element), which is cleaner and more desirable. So I suggest introducing a new cop that rewrites such cases.


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.

@r7kamura r7kamura force-pushed the array-intersect-with-single-element branch from a5d8af9 to c87d351 Compare September 8, 2025 06:10
@bbatsov bbatsov merged commit 4aa5418 into rubocop:master Sep 10, 2025
22 checks passed
@bbatsov
Copy link
Collaborator

bbatsov commented Sep 10, 2025

Seems like a reasonable suggestion to me. Thanks!

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.

2 participants