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

Highlight ruby debugger lines appropriately #16358

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

bostonaholic
Copy link
Sponsor Contributor

@bostonaholic bostonaholic commented Apr 4, 2024

Fixes #16357

The change expands the matching regex to only highlight lines where the debugger is the first word on a line.

The intended behavior is to highlight lines that are calling a ruby debugger. The purpose is to warn developers that might push code to production with a debugger enabled. The change expands the matching regex to only highlight lines where the debugger is the first word on a line.

There are cases in which the current regex is highlighting lines as a false-positive. I first noticed this in my Gemfile when it was highlighting the line below:

gem 'pry-byebug'

Other cases include: commented lines and defined function names that match a known debugger.

See below for cases in which the line should and should not be highlighted.

# frozen_string_literal: true

# This is a test class for ruby debugger highlighting
class Test
  # This line below should not be highlighted
  def byebug
    byebug # this line should be highlighted
    # byebug This comment shouldn't be highlighted

    binding.irb # this line should be highlighted
    # binding.irb this line should not be highlighted

    binding.pry # this line should be highlighted
    # binding.pry this line should not be highlighted
  end
end

Before:

Screenshot 2024-04-04 at 9 08 15 AM

After:

Screenshot 2024-04-04 at 9 12 23 AM

Fixes syl20bnr#16357

The change expands the matching regex to only highlight lines where the debugger
is the first word on a line.

The intended behavior is to highlight lines that are calling a ruby debugger.
The purpose is to warn developers that might push code to production
with a debugger enabled. The change expands the matching regex to only highlight
lines where the debugger is the first word on a line.

However, there are cases in which the regex is highlighting lines as a
false-positive. I first noticed this in my `Gemfile` when it was highlighting the
line below:

```ruby
gem 'pry-byebug'
```

Other cases include: commented lines and defined function names that match a known
debugger.

See below for cases in which the line should and should not be highlighted.

```ruby

class Test
  # This line below should not be highlighted
  def byebug
    byebug # this line should be highlighted
    # byebug This comment shouldn't be highlighted

    binding.irb # this line should be highlighted
    # binding.irb this line should not be highlighted

    binding.pry # this line should be highlighted
    # binding.pry this line should not be highlighted
  end
end
```
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.

Ruby debugger highlighting false-positives
1 participant