Skip to content

Commit 14a5c20

Browse files
marcandrebbatsov
authored andcommitted
Avoid comments_before_line
1 parent 8a02e42 commit 14a5c20

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

lib/rubocop/cop/layout/class_structure.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -269,15 +269,11 @@ def end_position_for(node)
269269
end
270270

271271
def begin_pos_with_comment(node)
272-
annotation_line = node.first_line - 1
273272
first_comment = nil
273+
(node.first_line - 1).downto(1) do |annotation_line|
274+
break unless (comment = processed_source.comment_at_line(annotation_line))
274275

275-
processed_source.comments_before_line(annotation_line)
276-
.reverse_each do |comment|
277-
if comment.location.line == annotation_line
278-
first_comment = comment
279-
annotation_line -= 1
280-
end
276+
first_comment = comment
281277
end
282278

283279
start_line_position(first_comment || node)

0 commit comments

Comments
 (0)