| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | require "rubocops/rubocop-cask" | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe RuboCop::Cop::Cask::ArrayAlphabetization, :config do | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  |   it "reports an offense when a single `zap trash` path is specified in an array" do | 
					
						
							| 
									
										
										
										
											2023-12-22 00:20:02 +00:00
										 |  |  |     expect_offense(<<~CASK) | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         zap trash: ["~/Library/Application Support/Foo"] | 
					
						
							| 
									
										
										
										
											2024-01-02 23:31:13 +00:00
										 |  |  |                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Avoid single-element arrays by removing the [] | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~CASK) | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         zap trash: "~/Library/Application Support/Foo" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-21 19:21:40 +00:00
										 |  |  |   it "reports an offense when the `zap` stanza paths are not in alphabetical order" do | 
					
						
							| 
									
										
										
										
											2023-12-22 00:20:02 +00:00
										 |  |  |     expect_offense(<<~CASK) | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         zap trash: [ | 
					
						
							| 
									
										
										
										
											2024-01-02 23:31:13 +00:00
										 |  |  |                    ^ The array elements should be ordered alphabetically | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  |           "/Library/Application Support/Foo", | 
					
						
							|  |  |  |           "/Library/Application Support/Baz", | 
					
						
							|  |  |  |           "~/Library/Application Support/Foo", | 
					
						
							|  |  |  |           "~/.dotfiles/thing", | 
					
						
							|  |  |  |           "~/Library/Application Support/Bar", | 
					
						
							| 
									
										
										
										
											2024-01-21 19:21:40 +00:00
										 |  |  |         ], | 
					
						
							|  |  |  |         rmdir: [ | 
					
						
							|  |  |  |                ^ The array elements should be ordered alphabetically | 
					
						
							|  |  |  |           "/Applications/foo/nested/blah", | 
					
						
							|  |  |  |           "/Applications/foo/", | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  |         ] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~CASK) | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         zap trash: [ | 
					
						
							|  |  |  |           "/Library/Application Support/Baz", | 
					
						
							|  |  |  |           "/Library/Application Support/Foo", | 
					
						
							|  |  |  |           "~/.dotfiles/thing", | 
					
						
							|  |  |  |           "~/Library/Application Support/Bar", | 
					
						
							|  |  |  |           "~/Library/Application Support/Foo", | 
					
						
							| 
									
										
										
										
											2024-01-21 19:21:40 +00:00
										 |  |  |         ], | 
					
						
							|  |  |  |         rmdir: [ | 
					
						
							|  |  |  |           "/Applications/foo/", | 
					
						
							|  |  |  |           "/Applications/foo/nested/blah", | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  |         ] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-12-21 20:21:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-12-22 00:22:33 +00:00
										 |  |  |   it "autocorrects alphabetization in zap trash paths with interpolation" do | 
					
						
							|  |  |  |     expect_offense(<<~CASK) | 
					
						
							| 
									
										
										
										
											2023-12-21 20:21:45 +00:00
										 |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         zap trash: [ | 
					
						
							| 
									
										
										
										
											2024-01-02 23:31:13 +00:00
										 |  |  |                    ^ The array elements should be ordered alphabetically | 
					
						
							| 
									
										
										
										
											2023-12-21 20:21:45 +00:00
										 |  |  |           "~/Library/Application Support/Foo", | 
					
						
							|  |  |  |           "~/Library/Application Support/Bar\#{version.major}", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2023-12-22 00:22:33 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~CASK) | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         zap trash: [ | 
					
						
							|  |  |  |           "~/Library/Application Support/Bar\#{version.major}", | 
					
						
							|  |  |  |           "~/Library/Application Support/Foo", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							| 
									
										
										
										
											2023-12-21 20:21:45 +00:00
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-12-22 00:41:56 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-02 23:31:13 +00:00
										 |  |  |   it "autocorrects alphabetization in `uninstall` methods" do | 
					
						
							|  |  |  |     expect_offense(<<~CASK) | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         uninstall pkgutil: [ | 
					
						
							|  |  |  |                            ^ The array elements should be ordered alphabetically | 
					
						
							|  |  |  |           "something", | 
					
						
							|  |  |  |           "other", | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         script: [ | 
					
						
							|  |  |  |           "ordered", | 
					
						
							|  |  |  |           "differently", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_correction(<<~CASK) | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         uninstall pkgutil: [ | 
					
						
							|  |  |  |           "other", | 
					
						
							|  |  |  |           "something", | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |         script: [ | 
					
						
							|  |  |  |           "ordered", | 
					
						
							|  |  |  |           "differently", | 
					
						
							|  |  |  |         ] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2024-01-14 21:32:50 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  |   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 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-20 00:03:03 +00:00
										 |  |  |   it "moves comments when autocorrecting" do | 
					
						
							| 
									
										
										
										
											2024-01-14 21:32:50 +00:00
										 |  |  |     expect_offense(<<~CASK) | 
					
						
							|  |  |  |       cask "foo" do | 
					
						
							|  |  |  |         url "https://example.com/foo.zip" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         zap trash: [ | 
					
						
							|  |  |  |                    ^ The array elements should be ordered alphabetically | 
					
						
							| 
									
										
										
										
											2024-01-20 00:03:03 +00:00
										 |  |  |           # comment related to foo | 
					
						
							| 
									
										
										
										
											2024-01-14 21:32:50 +00:00
										 |  |  |           "~/Library/Application Support/Foo", | 
					
						
							| 
									
										
										
										
											2024-01-21 12:42:22 +00:00
										 |  |  |           # a really long comment related to Zoo | 
					
						
							|  |  |  |           # and the Zoo comment continues | 
					
						
							|  |  |  |           "~/Library/Application Support/Zoo", | 
					
						
							| 
									
										
										
										
											2024-01-14 21:32:50 +00:00
										 |  |  |           "~/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: [ | 
					
						
							|  |  |  |           "~/Library/Application Support/Bar", | 
					
						
							|  |  |  |           "~/Library/Application Support/Baz", # in-line comment | 
					
						
							| 
									
										
										
										
											2024-01-20 00:03:03 +00:00
										 |  |  |           # comment related to foo | 
					
						
							| 
									
										
										
										
											2024-01-14 21:32:50 +00:00
										 |  |  |           "~/Library/Application Support/Foo", | 
					
						
							| 
									
										
										
										
											2024-01-21 12:42:22 +00:00
										 |  |  |           # a really long comment related to Zoo | 
					
						
							|  |  |  |           # and the Zoo comment continues | 
					
						
							|  |  |  |           "~/Library/Application Support/Zoo", | 
					
						
							| 
									
										
										
										
											2024-01-14 21:32:50 +00:00
										 |  |  |         ] | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     CASK | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2023-12-19 23:35:16 +00:00
										 |  |  | end |