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 a false positive for Lint/Debugger when methods containing different method chains #11552

Merged
merged 1 commit into from Feb 8, 2023

Conversation

ydah
Copy link
Member

@ydah ydah commented Feb 8, 2023

This PR is fix a false positive for Lint/Debugger when methods containing different method chains.

Motivation

I don't think that methods such as p.do_something for example should be an offense of this cop. I think it would be better to make it a violation only if it is an exact match, including the method chain, but what do you think?

This PR will result in the following

# bad
p 'foo'
foo(p 'foo')
p(p 'foo')

# good
p.do_something # <--- Before the change, it is a bad code
Foo.p

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.

…erent method chains

This PR is fix a false positive for `Lint/Debugger` when methods containing different method chains.

## Motivation
I don't think that methods such as `p.do_something` for example should be an offense of this cop.
I think it would be better to make it a violation only if it is an exact match, including the method chain, but what do you think?

## This PR will result in the following

```ruby
# bad
p 'foo'
foo(p 'foo')
p(p 'foo')

# good
p.do_something
Foo.p
```
@bbatsov bbatsov merged commit 2989584 into rubocop:master Feb 8, 2023
@bbatsov
Copy link
Collaborator

bbatsov commented Feb 8, 2023

Yeah, I agree that's an improvement. Thanks!

@hartator
Copy link

hartator commented Feb 9, 2023

Thanks for all the work @ydah. Good job and it's deeply appreciated. ❤️

This has immediately created an issue on our end unfortunately. We use Lint/Debugger to catch potential forgotten binding.pry. However, we also do have legitimate utility scripts that uses p and pp to add some verbosity to their outputs. These are not forgotten and are on purpose.

Maybe it makes sense to move p and pp outside of Lint/Debugger? To something like Lint/DebuggerPrints? And keep Lint/Debugger only for REPLs?

@koic
Copy link
Member

koic commented Feb 9, 2023

p and pp were added for debugging methods that call inspect (not to_s) internally.
#11518

@ydah ydah deleted the fix-lint-debugger branch February 9, 2023 01:58
@hartator
Copy link

p and pp were added for debugging methods that call inspect (not to_s) internally.
#11518

Why not catching .inspect as well then? Following this logic, .inspect should be also used only for debugging and shouldn't be in a production codebase. However, there are out there legitimate use cases of this as well. I would believe this opens up a bad rabbit hole.

Can you guys reconsider? The current implementation will make us remove Lint/Debugger as a linter unfortunately.

koic added a commit to koic/rubocop that referenced this pull request Feb 10, 2023
This PR rolls back the print debug default configuration (rubocop#11518) of `Lint/Debugger`
based on the following feedback.

- rubocop#11557 (comment)
- rubocop#11552 (comment)
- rubocop#11518 (comment)

It seems like it was a bad idea to mix debugger and print debug methods by default.

This PR updates `Lint/Debugger` cop defaults to handle only debugger methods as per the cop name.
OTOH, it leaves the logic in rubocop#11557 to prevent false positives when user configures
print debug methods. e.g. rubocop#11517 (comment)
@koic
Copy link
Member

koic commented Feb 10, 2023

I reconsidered based on some feedback and opened #11564. Thank you.

@hartator
Copy link

I reconsidered based on some feedback and opened #11564. Thank you.

Thank you. 👍

bbatsov pushed a commit that referenced this pull request Feb 11, 2023
This PR rolls back the print debug default configuration (#11518) of `Lint/Debugger`
based on the following feedback.

- #11557 (comment)
- #11552 (comment)
- #11518 (comment)

It seems like it was a bad idea to mix debugger and print debug methods by default.

This PR updates `Lint/Debugger` cop defaults to handle only debugger methods as per the cop name.
OTOH, it leaves the logic in #11557 to prevent false positives when user configures
print debug methods. e.g. #11517 (comment)
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.

None yet

4 participants