KEMBAR78
Fix wrong autocorrect for `Style/For` with save navigation in the collection by Earlopain · Pull Request #14459 · rubocop/rubocop · GitHub
Skip to content

Conversation

@Earlopain
Copy link
Contributor

In such a case calling each is not safe without also using safe navigation.

Lint/Lint/SafeNavigationChain would pick this up so it's not a big deal but it's also not difficult to do the correct thing directly.


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.

extend NodePattern::Macros

CORRECTION = '%<collection>s.each do |%<argument>s|'
CORRECTION = '%<collection>s%<dot>seach do |%<argument>s|' # codespell:ignore
Copy link
Contributor Author

Choose a reason for hiding this comment

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

codespell thinks seach should be search or something similar to it

Copy link
Member

Choose a reason for hiding this comment

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

Can you specify it in the .codespellrc file instead of using the # codespell:ignore comment annotation?
https://github.com/rubocop/rubocop/blob/master/.codespellrc

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Seemed better to me to add it inline instead of allowing it everywhere. I added it to the config instead.

…lection

In such a case calling `each` is not safe without also using safe navigation.

`Lint/Lint/SafeNavigationChain` would pick this up so it's not a big deal but it's also not difficult to do the correct thing directly.
@koic koic merged commit 34d0892 into rubocop:master Aug 18, 2025
22 checks passed
@Earlopain Earlopain deleted the style-for-safe-nav branch September 3, 2025 12:10
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