Skip to content

Conversation

@vlad-pisanov
Copy link
Contributor

Small improvement to Style/MapIntoArray's autocorrection detection.

This cop can only autocorrect in a void context, and currently it only checks (kw)begin/(num)block contexts. This PR adapts some of the new logic from Lint/Void to expand void context detection to ensure, def, defs, and for contexts by delegating the responsibility to rubocop-ast.

e.g.

def initialize
  dest = []
  list.each { dest << _1 } # 🆕 can now be autocorrected since it's in constructor
end
def self.name=(value)
  dest = []
  list.each { dest << _1 } # 🆕 can now be autocorrected since it's in an assignment method
end
def foo
  bar
ensure
  dest = []
  list.each { dest << _1 } # 🆕 can now be autocorrected since ensure is always a void context
end
for i in list
  dest = []
  list.each { dest << _1 } # 🆕 can now be autocorrected since it's in a for loop
end

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.

@koic koic merged commit 5e65a39 into rubocop:master Sep 3, 2024
@koic
Copy link
Member

koic commented Sep 3, 2024

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