Skip to content

Commit

Permalink
Treat zap and uninstall the same
Browse files Browse the repository at this point in the history
- Since `zap` can have more than just `trash`.
  • Loading branch information
issyl0 committed Jan 21, 2024
1 parent d5f9eef commit 57757ef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 18 deletions.
5 changes: 1 addition & 4 deletions Library/Homebrew/rubocops/cask/array_alphabetization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@ def on_send(node)

node.each_descendant(:pair).each do |pair|
symbols = pair.children.select(&:sym_type?).map(&:value)
# For `zap`s, we only care about `trash` arrays.
next if name == :zap && !symbols.include?(:trash)
# Don't order `uninstall` arrays that contain commands.
next if name == :uninstall && symbols.intersect?([:signal, :script, :early_script, :args, :input])
next if symbols.intersect?([:signal, :script, :early_script, :args, :input])

pair.each_descendant(:array).each do |array|
if array.children.length == 1
Expand Down
24 changes: 10 additions & 14 deletions Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
CASK
end

it "reports an offense when the `zap trash` paths are not in alphabetical order" do
it "reports an offense when the `zap` stanza paths are not in alphabetical order" do
expect_offense(<<~CASK)
cask "foo" do
url "https://example.com/foo.zip"
Expand All @@ -34,6 +34,11 @@
"~/Library/Application Support/Foo",
"~/.dotfiles/thing",
"~/Library/Application Support/Bar",
],
rmdir: [
^ The array elements should be ordered alphabetically
"/Library/Application Support/token/foo",
"/Library/Application Support/token/bar",
]
end
CASK
Expand All @@ -48,6 +53,10 @@
"~/.dotfiles/thing",
"~/Library/Application Support/Bar",
"~/Library/Application Support/Foo",
],
rmdir: [
"/Library/Application Support/dir/bar",
"/Library/Application Support/dir/foo",
]
end
CASK
Expand Down Expand Up @@ -78,19 +87,6 @@
CASK
end

it "ignores `zap` methods other than `trash`" do
expect_no_offenses(<<~CASK)
cask "foo" do
url "https://example.com/foo.zip"
zap delete: [
"~/Library/Application Support/Foo",
"~/Library/Application Support/Bar",
]
end
CASK
end

it "autocorrects alphabetization in `uninstall` methods" do
expect_offense(<<~CASK)
cask "foo" do
Expand Down

0 comments on commit 57757ef

Please sign in to comment.