From f4754baa0070adf191f56bc0685668ddc9734907 Mon Sep 17 00:00:00 2001 From: Issy Long Date: Thu, 21 Dec 2023 20:21:45 +0000 Subject: [PATCH] Ignore `zap trash` stanzas with interpolation - Interpolating the version into a path is a common pattern, but the interpolations trip up the alphabetization autocorrect quite spectacularly, so let's ignore them (for now?). --- .../Homebrew/rubocops/cask/array_alphabetization.rb | 2 +- .../rubocops/cask/array_alphabetization_spec.rb | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/Library/Homebrew/rubocops/cask/array_alphabetization.rb b/Library/Homebrew/rubocops/cask/array_alphabetization.rb index b4c0bc50fe..3ee5dbbf28 100644 --- a/Library/Homebrew/rubocops/cask/array_alphabetization.rb +++ b/Library/Homebrew/rubocops/cask/array_alphabetization.rb @@ -18,7 +18,7 @@ module RuboCop end end - array.each_descendant(:str).each_cons(2) do |first, second| + array.children.reject(&:dstr_type?).each_cons(2) do |first, second| next if first.source.downcase < second.source.downcase add_offense(second, message: "The `zap trash` paths should be in alphabetical order") do |corrector| diff --git a/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb b/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb index fddcf0ac2a..cd84115fe8 100644 --- a/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb @@ -56,4 +56,17 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do end CASK end + + it "ignores zap trash paths that have interpolation" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap trash: [ + "~/Library/Application Support/Foo", + "~/Library/Application Support/Bar\#{version.major}", + ] + end + CASK + end end