Skip to content

Commit

Permalink
Speed up
Browse files Browse the repository at this point in the history
  • Loading branch information
hoshinotsuyoshi committed Jan 29, 2024
1 parent cc1a5ec commit b512b93
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 3 additions & 4 deletions lib/rubocop/cop/grep/grep.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ def on_new_investigation
re = Regexp.new(pat, opt)
from = 0
while m = re.match(source, from)
if match_comment || !in_comment?(m)
pos = position_from_matchdata(m)
pos = position_from_matchdata(m)
if match_comment || !in_comment?(pos)
range = source_range(processed_source.buffer, pos[:line], pos[:column], pos[:length])
add_offense(range, message: rule['Message'])
end
Expand All @@ -42,8 +42,7 @@ def on_new_investigation
{ line: line, column: column, length: length }
end

private def in_comment?(m)
pos = position_from_matchdata(m)
private def in_comment?(pos)
processed_source.comments.any? do |c|
c.loc.line == pos[:line] && c.loc.expression.begin_pos <= pos[:column]
end
Expand Down
6 changes: 5 additions & 1 deletion sig/rubocop/cop/cop/grep.rbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ module RuboCop
length: Integer,
}

private def in_comment?: (MatchData) -> bool
private def in_comment?: ({
line: Integer,
column: Integer,
length: Integer,
}) -> bool

private def regexp_option: (rule) -> Integer

Expand Down

0 comments on commit b512b93

Please sign in to comment.