Skip to content

Commit 59c7df6

Browse files
committed
rubocops: ignore uninstall opt-ins
Teach UninstallMethodsOrder to ignore quit_on_upgrade and signal_on_upgrade metadata keys when checking uninstall/zap method order, and add a spec case covering this.
1 parent 1b49c69 commit 59c7df6

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

Library/Homebrew/rubocops/cask/uninstall_methods_order.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,13 @@ class UninstallMethodsOrder < Base
1313

1414
MSG = T.let("`%<method>s` method out of order", String)
1515

16+
# These keys are ignored when checking method order.
17+
# Mirrors AbstractUninstall::UPGRADE_METADATA_KEYS.
18+
UPGRADE_METADATA_KEYS = T.let(
19+
[:quit_on_upgrade, :signal_on_upgrade].freeze,
20+
T::Array[Symbol],
21+
)
22+
1623
sig { params(node: AST::SendNode).void }
1724
def on_send(node)
1825
return unless [:zap, :uninstall].include?(node.method_name)
@@ -21,6 +28,12 @@ def on_send(node)
2128
return if hash_node.nil? || (!hash_node.is_a?(AST::Node) && !hash_node.hash_type?)
2229

2330
method_nodes = hash_node.pairs.map(&:key)
31+
32+
method_nodes = method_nodes.reject do |method|
33+
name = method.children.first
34+
UPGRADE_METADATA_KEYS.include?(name)
35+
end
36+
2437
expected_order = method_nodes.sort_by { |method| method_order_index(method) }
2538
comments = processed_source.comments
2639

Library/Homebrew/test/rubocops/cask/uninstall_methods_order_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,28 @@
7878
end
7979
CASK
8080
end
81+
82+
it "ignores opt-in boolean keys such as quit_on_upgrade and signal_on_upgrade" do
83+
expect_no_offenses(<<~CASK)
84+
cask "foo" do
85+
url "https://example.com/foo.zip"
86+
87+
uninstall quit: "com.example.foo",
88+
quit_on_upgrade: true,
89+
signal: ["TERM", "com.example.foo"],
90+
signal_on_upgrade: true,
91+
script: {
92+
executable: "/usr/local/bin/foo",
93+
sudo: false,
94+
},
95+
pkgutil: "org.foo.bar",
96+
delete: [
97+
"/usr/local/bin/foo",
98+
"/usr/local/bin/foobar",
99+
]
100+
end
101+
CASK
102+
end
81103
end
82104

83105
context "with a single method" do

0 commit comments

Comments
 (0)