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 #9500] Update Lint/Debugger so that only specific receivers for debug methods lead to offenses #9504

Merged
merged 1 commit into from Feb 12, 2021

Conversation

dvandersluis
Copy link
Member

Prior to #8929, Lint/Debugger looked for a specific receiver/method pair, but that PR changed it so that any of the DebuggerReceivers would apply, or also no receiver. This caused regressions (#7636 and #9500, for instance) because method names specified as debugger by this cop would now register offenses when called with no receiver.

In order to fix it, I changed the configuration for Lint/Debugger a bit, but in a way that should not cause any major incompatibility. The allow list is now specified including its receiver so that the receiver can be checked. Existing configurations that just pass in a method name will be treated as expecting no receiver (there's a slight incompatibility there because previously foo would be matched by Kernel.foo but I think this is ok (and is resolvable by adding Kernel.foo to the configuration).

I've also grouped the debugger methods by source (it's often confusing to me where each method comes from), which also allows an end-user to disable a pre-defined group of methods by specifying Byebug: ~ for example.

Finally I've deprecated the DebuggerReceivers configuration as it is no longer useful.

Fixes #9500.


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.

…vers for debug methods lead to offenses.

Prior to rubocop#8929, `Lint/Debugger` looked for a specific receiver/method pair, but that PR changed it so that any of the `DebuggerReceivers` would apply, *or also* no receiver. This caused regressions (rubocop#7636 and rubocop#9500, for instance) because method names specified as debugger by this cop would now register offenses when called with no receiver.

In order to fix it, I changed the configuration for `Lint/Debugger` a bit, but in a way that should not cause any major incompatibility. The allow list is now specified including its receiver so that the receiver can be checked. Existing configurations that just pass in a method name will be treated as expecting no receiver (there's a slight incompatibility there because previously `foo` would be matched by `Kernel.foo` but I think this is ok (and is resolvable by adding `Kernel.foo` to the configuration).

I've also grouped the debugger methods by source (it's often confusing to me where each method comes from), which also allows an end-user to disable a pre-defined group of methods by specifying `Byebug: ~` for example.

Finally I've deprecated the `DebuggerReceivers` configuration as it is no longer useful.
Comment on lines -164 to -168
it 'reports an offense for save_and_open_page with Kernel' do
expect_offense(<<~RUBY)
Kernel.save_and_open_page
^^^^^^^^^^^^^^^^^^^^^^^^^ Remove debugger entry point `Kernel.save_and_open_page`.
RUBY
Copy link
Member Author

Choose a reason for hiding this comment

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

This test was discussed in #8929 as being there because it was not possible to exclude it in the way the cop was changed, but capybara does not actually add the method to Kernel so it's a false positive that I've now removed.

- Kernel
- Pry
VersionChanged: <<next>>
DebuggerReceivers: [] # deprecated
Copy link
Member Author

Choose a reason for hiding this comment

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

I didn't want users to get error messages about an invalid configuration (in case they've set this) so I've added it to the obsoletion config (with warning severity) but kept the configuration.

@bbatsov bbatsov merged commit b82c20f into rubocop:master Feb 12, 2021
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 12, 2021

Fantastic work! Quite the improvement over the previous configuration setup of the cop.

@bquorning bquorning mentioned this pull request Feb 17, 2021
8 tasks
@dvandersluis dvandersluis deleted the issue/9500 branch September 14, 2021 16:04
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.

Lint/Debugger complains about using "console" when it is not appropriate
2 participants