Cache Stanza#comments.
This commit is contained in:
parent
6e6493bd1b
commit
8b9ee05118
@ -28,7 +28,7 @@ module RuboCop
|
|||||||
end
|
end
|
||||||
|
|
||||||
def source_range_with_comments
|
def source_range_with_comments
|
||||||
stanza_comments(stanza_node).reduce(source_range) do |range, comment|
|
comments.reduce(source_range) do |range, comment|
|
||||||
range.join(comment.loc.expression)
|
range.join(comment.loc.expression)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -51,8 +51,8 @@ module RuboCop
|
|||||||
stanza_group == other.stanza_group
|
stanza_group == other.stanza_group
|
||||||
end
|
end
|
||||||
|
|
||||||
def stanza_comments(stanza_node)
|
def comments
|
||||||
stanza_node.each_node.reduce([]) do |comments, node|
|
@comments ||= stanza_node.each_node.reduce([]) do |comments, node|
|
||||||
comments | comments_hash[node.loc]
|
comments | comments_hash[node.loc]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -60,7 +60,7 @@ module RuboCop
|
|||||||
def comments_hash
|
def comments_hash
|
||||||
@comments_hash ||= Parser::Source::Comment.associate_locations(
|
@comments_hash ||= Parser::Source::Comment.associate_locations(
|
||||||
stanza_node.parent,
|
stanza_node.parent,
|
||||||
stanza_comments(stanza_node),
|
comments,
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user