Skip to content

Commit

Permalink
Only match comments for the current block node
Browse files Browse the repository at this point in the history
Note: comments can span multiple lines, so check against all lines.
  • Loading branch information
jeromedalbert committed Nov 14, 2024
1 parent 413fe78 commit 49fc0ac
Showing 1 changed file with 2 additions and 4 deletions.
6 changes: 2 additions & 4 deletions lib/rubocop/cop/obsession/rails/safety_assured_comment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,9 @@ class SafetyAssuredComment < Base

def on_block(node)
return if !safety_assured_block?(node)
previous_comment = processed_source.comments_before_line(node.first_line)&.last
comment = processed_source.ast_with_comments[node].map(&:text).join("\n")

if previous_comment.nil? || !previous_comment.text.match?(/^# Safe because( [^ ]+){4}/)
add_offense(node)
end
add_offense(node) if !comment.match?(/^# Safe because( [^ ]+){4}/)
end
end
end
Expand Down

0 comments on commit 49fc0ac

Please sign in to comment.