KEMBAR78
Change `Lint/ConstantOverwrittenInRescue` to detect any constant assignment by viralpraxis · Pull Request #14596 · rubocop/rubocop · GitHub
Skip to content

Conversation

@viralpraxis
Copy link
Contributor

Since the receiver of a constant assignment can be a method call (or a variable), I think it makes sense to remove the "const receiver" restriction.


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.
  • 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.

begin
something
rescue => foo.class::RESCUABLE_EXCEPTIONS
^^ `RESCUABLE_EXCEPTIONS` is overwritten by `rescue =>`.
Copy link
Member

Choose a reason for hiding this comment

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

For this cop’s message, showing the entire exception class name as below would probably make the intention clearer.

Suggested change
^^ `RESCUABLE_EXCEPTIONS` is overwritten by `rescue =>`.
^^ `foo.class::RESCUABLE_EXCEPTIONS` is overwritten by `rescue =>`.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

…gnment

Since the receiver of a constant assignment can be a method call (or a variable),
I think it makes sense to remove the "const receiver" restriction.
@viralpraxis viralpraxis force-pushed the change-lint-constant-overriden-in-rescue-to-detect-any-constant-assignment branch from 3eec280 to 1f8ffa5 Compare October 11, 2025 17:00
@koic koic merged commit 8c21dd7 into rubocop:master Oct 12, 2025
22 checks passed
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