From 7a4a5798478a62f1c57e1bcfa7071279f135ffe8 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Tue, 21 Mar 2023 00:12:28 +0000 Subject: [PATCH] rubocops/cask: Run `on_system_stanzas(on_block)` once in the beginning Co-authored-by: Markus Reiter --- Library/Homebrew/rubocops/cask/no_overrides.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/cask/no_overrides.rb b/Library/Homebrew/rubocops/cask/no_overrides.rb index 159e355da8..6d1dbbf186 100644 --- a/Library/Homebrew/rubocops/cask/no_overrides.rb +++ b/Library/Homebrew/rubocops/cask/no_overrides.rb @@ -20,13 +20,15 @@ module RuboCop # Skip if there are no `on_*` blocks. return unless (on_blocks = cask_stanzas.select { |s| ON_SYSTEM_METHODS.include?(s.stanza_name) }).any? + stanzas_in_blocks = on_system_stanzas(on_blocks) + cask_stanzas.each do |stanza| # Skip if the stanza is itself an `on_*` block. next if ON_SYSTEM_METHODS.include?(stanza.stanza_name) # Skip if the stanza we detect is already in an `on_*` block. next if stanza.parent_node.block_type? && ON_SYSTEM_METHODS.include?(stanza.parent_node.method_name) # Skip if the stanza outside of a block is not also in an `on_*` block. - next unless on_system_stanzas(on_blocks).include?(stanza.stanza_name) + next unless stanzas_in_blocks.include?(stanza.stanza_name) add_offense(stanza.source_range, message: format(MESSAGE, stanza: stanza.stanza_name)) end