diff --git a/Library/Homebrew/rubocops/cask/array_alphabetization.rb b/Library/Homebrew/rubocops/cask/array_alphabetization.rb index de52dddb9c..d6ca7f3ca3 100644 --- a/Library/Homebrew/rubocops/cask/array_alphabetization.rb +++ b/Library/Homebrew/rubocops/cask/array_alphabetization.rb @@ -8,14 +8,11 @@ module RuboCop extend AutoCorrector 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| 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 diff --git a/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb b/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb index ad5a2b98a1..da981e714b 100644 --- a/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb @@ -22,7 +22,7 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do 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" @@ -34,6 +34,11 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do "~/Library/Application Support/Foo", "~/.dotfiles/thing", "~/Library/Application Support/Bar", + ], + rmdir: [ + ^ The array elements should be ordered alphabetically + "/Applications/foo/nested/blah", + "/Applications/foo/", ] end CASK @@ -48,6 +53,10 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do "~/.dotfiles/thing", "~/Library/Application Support/Bar", "~/Library/Application Support/Foo", + ], + rmdir: [ + "/Applications/foo/", + "/Applications/foo/nested/blah", ] end CASK @@ -78,19 +87,6 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do 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 diff --git a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb index 706ca7a2f1..1e7f57ea1f 100644 --- a/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb +++ b/Library/Homebrew/test/support/fixtures/cask/Casks/with-zap-delete.rb @@ -9,9 +9,9 @@ cask "with-zap-delete" do zap delete: [ "#{TEST_TMPDIR}/absolute_path", - "~/path_with_tilde", "#{TEST_TMPDIR}/glob_path*", - "impermissible/relative/path", "/another/impermissible/../relative/path", + "impermissible/relative/path", + "~/path_with_tilde", ] end