Skip to content

Commit

Permalink
Leverage def_node_matcher yielding its match
Browse files Browse the repository at this point in the history
  • Loading branch information
Darhazer authored and bquorning committed Oct 21, 2022
1 parent 1858d16 commit 7dd4917
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions lib/rubocop/cop/rspec/sort_metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,17 @@ class SortMetadata < Base

# @!method metadata_in_block(node)
def_node_search :metadata_in_block, <<~PATTERN
(send (lvar $_) #Hooks.all _ ${send str sym}* (hash $...)?)
(send (lvar %) #Hooks.all _ ${send str sym}* (hash $...)?)
PATTERN

def on_block(node)
if (block_var = rspec_configure(node))
metadata_in_block(node).each do |receiver, symbols, pairs|
investigate(symbols, pairs.flatten) if receiver == block_var
rspec_configure(node) do |block_var|
metadata_in_block(node, block_var) do |symbols, pairs|
investigate(symbols, pairs.flatten)
end
elsif (symbols, pairs = rspec_metadata(node))
end

rspec_metadata(node) do |symbols, pairs|
investigate(symbols, pairs.flatten)
end
end
Expand Down

0 comments on commit 7dd4917

Please sign in to comment.