Treat zap and uninstall the same

- Since `zap` can have more than just `trash`.
This commit is contained in:
Issy Long 2024-01-21 19:21:40 +00:00
parent d5f9eef1b5
commit 693a27d48b
No known key found for this signature in database
GPG Key ID: 8247C390DADC67D4
3 changed files with 14 additions and 21 deletions

View File

@ -8,14 +8,11 @@ module RuboCop
extend AutoCorrector extend AutoCorrector
def on_send(node) def on_send(node)
return unless [:zap, :uninstall].include?(name = node.method_name) return unless [:zap, :uninstall].include?(node.method_name)
node.each_descendant(:pair).each do |pair| node.each_descendant(:pair).each do |pair|
symbols = pair.children.select(&:sym_type?).map(&:value) symbols = pair.children.select(&:sym_type?).map(&:value)
# For `zap`s, we only care about `trash` arrays. next if symbols.intersect?([:signal, :script, :early_script, :args, :input])
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])
pair.each_descendant(:array).each do |array| pair.each_descendant(:array).each do |array|
if array.children.length == 1 if array.children.length == 1

View File

@ -22,7 +22,7 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
CASK CASK
end 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) expect_offense(<<~CASK)
cask "foo" do cask "foo" do
url "https://example.com/foo.zip" url "https://example.com/foo.zip"
@ -34,6 +34,11 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
"~/Library/Application Support/Foo", "~/Library/Application Support/Foo",
"~/.dotfiles/thing", "~/.dotfiles/thing",
"~/Library/Application Support/Bar", "~/Library/Application Support/Bar",
],
rmdir: [
^ The array elements should be ordered alphabetically
"/Applications/foo/nested/blah",
"/Applications/foo/",
] ]
end end
CASK CASK
@ -48,6 +53,10 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
"~/.dotfiles/thing", "~/.dotfiles/thing",
"~/Library/Application Support/Bar", "~/Library/Application Support/Bar",
"~/Library/Application Support/Foo", "~/Library/Application Support/Foo",
],
rmdir: [
"/Applications/foo/",
"/Applications/foo/nested/blah",
] ]
end end
CASK CASK
@ -78,19 +87,6 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do
CASK CASK
end 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 it "autocorrects alphabetization in `uninstall` methods" do
expect_offense(<<~CASK) expect_offense(<<~CASK)
cask "foo" do cask "foo" do

View File

@ -9,9 +9,9 @@ cask "with-zap-delete" do
zap delete: [ zap delete: [
"#{TEST_TMPDIR}/absolute_path", "#{TEST_TMPDIR}/absolute_path",
"~/path_with_tilde",
"#{TEST_TMPDIR}/glob_path*", "#{TEST_TMPDIR}/glob_path*",
"impermissible/relative/path",
"/another/impermissible/../relative/path", "/another/impermissible/../relative/path",
"impermissible/relative/path",
"~/path_with_tilde",
] ]
end end