From e4b4af4c456397db3ae4a67272f38134a0075d7c Mon Sep 17 00:00:00 2001 From: Issy Long Date: Sun, 14 Jan 2024 21:32:50 +0000 Subject: [PATCH] Add a failing test for comments moving with the alphabetization --- .../cask/array_alphabetization_spec.rb | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb b/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb index d576ef9573..3f2a7c6623 100644 --- a/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb +++ b/Library/Homebrew/test/rubocops/cask/array_alphabetization_spec.rb @@ -123,4 +123,46 @@ describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do end CASK end + + it "ignores `uninstall` methods with commands" do + expect_no_offenses(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + uninstall script: { + args: ["--mode=something", "--another-mode"], + executable: "thing", + } + end + CASK + end + + focus it "moves comments when autocorrecting" do + expect_offense(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap trash: [ + ^ The array elements should be ordered alphabetically + # overall comment, shouldn't move + "~/Library/Application Support/Foo", + "~/Library/Application Support/Bar", + "~/Library/Application Support/Baz", # in-line comment + ] + end + CASK + + expect_correction(<<~CASK) + cask "foo" do + url "https://example.com/foo.zip" + + zap trash: [ + # overall comment, shouldn't move + "~/Library/Application Support/Bar", + "~/Library/Application Support/Baz", # in-line comment + "~/Library/Application Support/Foo", + ] + end + CASK + end end