Fix toplevel_stanzas
.
This commit is contained in:
parent
8c6f31a7ac
commit
3c89f99df1
@ -36,7 +36,15 @@ module RuboCop
|
||||
end
|
||||
|
||||
def toplevel_stanzas
|
||||
@toplevel_stanzas ||= stanzas.select(&:toplevel_stanza?)
|
||||
# If a `cask` block only contains one stanza, it is that stanza's direct parent,
|
||||
# otherwise stanzas are grouped in a block and `cask` is that block's parent.
|
||||
is_toplevel_stanza = if cask_body.begin_block?
|
||||
->(stanza) { stanza.parent_node.parent.cask_block? }
|
||||
else
|
||||
->(stanza) { stanza.parent_node.cask_block? }
|
||||
end
|
||||
|
||||
@toplevel_stanzas ||= stanzas.select(&is_toplevel_stanza)
|
||||
end
|
||||
|
||||
def sorted_toplevel_stanzas
|
||||
|
@ -52,10 +52,6 @@ module RuboCop
|
||||
stanza_group == other.stanza_group
|
||||
end
|
||||
|
||||
def toplevel_stanza?
|
||||
parent_node.cask_block? || parent_node.parent.cask_block?
|
||||
end
|
||||
|
||||
def ==(other)
|
||||
self.class == other.class && stanza_node == other.stanza_node
|
||||
end
|
||||
|
@ -17,6 +17,8 @@ module RuboCop
|
||||
def_node_matcher :cask_block?, "(block (send nil? :cask _) args ...)"
|
||||
def_node_matcher :arch_variable?, "(lvasgn _ (send nil? :on_arch_conditional ...))"
|
||||
|
||||
def_node_matcher :begin_block?, "(begin ...)"
|
||||
|
||||
def stanza?
|
||||
return true if arch_variable?
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user