| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 19:41:14 +01:00
										 |  |  | require "rubocops/dependency_order" | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-18 15:11:11 -08:00
										 |  |  | RSpec.describe RuboCop::Cop::FormulaAudit::DependencyOrder do | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |   context "when auditing `uses_from_macos`" do | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects incorrectly ordered conditional dependencies" do | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |           uses_from_macos "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 5) should be put before dependency "apple" (line 4) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect_correction(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           uses_from_macos "foo" => :optional | 
					
						
							|  |  |  |           uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects incorrectly ordered alphabetical dependencies" do | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           uses_from_macos "foo" | 
					
						
							|  |  |  |           uses_from_macos "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 5) should be put before dependency "foo" (line 4) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect_correction(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           uses_from_macos "bar" | 
					
						
							|  |  |  |           uses_from_macos "foo" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects incorrectly ordered dependencies that are Requirements" do | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           uses_from_macos FooRequirement | 
					
						
							|  |  |  |           uses_from_macos "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 5) should be put before dependency "FooRequirement" (line 4) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect_correction(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           uses_from_macos "bar" | 
					
						
							|  |  |  |           uses_from_macos FooRequirement | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects wrong conditional order within a spec block" do | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           head do | 
					
						
							|  |  |  |             uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |             uses_from_macos "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 6) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |             uses_from_macos "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 7) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |           end | 
					
						
							|  |  |  |           uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |           uses_from_macos "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 10) should be put before dependency "apple" (line 9) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect_correction(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           head do | 
					
						
							|  |  |  |             uses_from_macos "bar" | 
					
						
							|  |  |  |             uses_from_macos "foo" => :optional | 
					
						
							|  |  |  |             uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           uses_from_macos "foo" => :optional | 
					
						
							|  |  |  |           uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |     it "reports no offenses if correct order for multiple tags" do | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           uses_from_macos "bar" => [:build, :test] | 
					
						
							|  |  |  |           uses_from_macos "foo" => :build | 
					
						
							|  |  |  |           uses_from_macos "apple" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-08-02 23:04:28 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "reports and corrects wrong conditional order within a system block" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           on_arm do | 
					
						
							|  |  |  |             uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |             uses_from_macos "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 6) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2022-08-02 23:04:28 -07:00
										 |  |  |             uses_from_macos "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 7) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2022-08-02 23:04:28 -07:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect_correction(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           on_arm do | 
					
						
							|  |  |  |             uses_from_macos "bar" | 
					
						
							|  |  |  |             uses_from_macos "foo" => :optional | 
					
						
							|  |  |  |             uses_from_macos "apple" if build.with? "foo" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-23 18:02:25 -08:00
										 |  |  |   context "when auditing `depends_on`" do | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects incorrectly ordered conditional dependencies" do | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |           depends_on "apple" if build.with? "foo" | 
					
						
							|  |  |  |           depends_on "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 5) should be put before dependency "apple" (line 4) | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           depends_on "foo" => :optional | 
					
						
							|  |  |  |           depends_on "apple" if build.with? "foo" | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects incorrectly ordered alphabetical dependencies" do | 
					
						
							| 
									
										
										
										
											2018-06-11 04:21:02 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           depends_on "foo" | 
					
						
							| 
									
										
										
										
											2018-06-11 04:21:02 +02:00
										 |  |  |           depends_on "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 5) should be put before dependency "foo" (line 4) | 
					
						
							| 
									
										
										
										
											2018-06-11 04:21:02 +02:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           depends_on "bar" | 
					
						
							|  |  |  |           depends_on "foo" | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-03-28 20:54:39 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects incorrectly ordered dependencies that are Requirements" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2018-03-28 20:54:39 -05:00
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           depends_on FooRequirement | 
					
						
							|  |  |  |           depends_on "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 5) should be put before dependency "FooRequirement" (line 4) | 
					
						
							| 
									
										
										
										
											2018-03-28 20:54:39 -05:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           depends_on "bar" | 
					
						
							|  |  |  |           depends_on FooRequirement | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports and corrects wrong conditional order within a spec block" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           head do | 
					
						
							|  |  |  |             depends_on "apple" if build.with? "foo" | 
					
						
							|  |  |  |             depends_on "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 6) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |             depends_on "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 7) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           end | 
					
						
							|  |  |  |           depends_on "apple" if build.with? "foo" | 
					
						
							|  |  |  |           depends_on "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 10) should be put before dependency "apple" (line 9) | 
					
						
							| 
									
										
										
										
											2020-01-12 10:59:22 -08:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           head do | 
					
						
							|  |  |  |             depends_on "bar" | 
					
						
							|  |  |  |             depends_on "foo" => :optional | 
					
						
							|  |  |  |             depends_on "apple" if build.with? "foo" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |           depends_on "foo" => :optional | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           depends_on "apple" if build.with? "foo" | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |     it "reports no offenses if correct order for multiple tags" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							| 
									
										
										
										
											2021-01-12 14:52:47 +11:00
										 |  |  |           depends_on "bar" => [:build, :test] | 
					
						
							|  |  |  |           depends_on "foo" => :build | 
					
						
							|  |  |  |           depends_on "apple" | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2018-07-11 15:17:40 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2022-08-02 23:04:28 -07:00
										 |  |  | 
 | 
					
						
							|  |  |  |     it "reports and corrects wrong conditional order within a system block" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           on_linux do | 
					
						
							|  |  |  |             depends_on "apple" if build.with? "foo" | 
					
						
							|  |  |  |             depends_on "bar" | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "bar" (line 6) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2022-08-02 23:04:28 -07:00
										 |  |  |             depends_on "foo" => :optional | 
					
						
							| 
									
										
										
										
											2023-04-07 17:16:48 +01:00
										 |  |  |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ FormulaAudit/DependencyOrder: dependency "foo" (line 7) should be put before dependency "apple" (line 5) | 
					
						
							| 
									
										
										
										
											2022-08-02 23:04:28 -07:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |       expect_correction(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           homepage "https://brew.sh" | 
					
						
							|  |  |  |           url "https://brew.sh/foo-1.0.tgz" | 
					
						
							|  |  |  |           on_linux do | 
					
						
							|  |  |  |             depends_on "bar" | 
					
						
							|  |  |  |             depends_on "foo" => :optional | 
					
						
							|  |  |  |             depends_on "apple" if build.with? "foo" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2018-02-19 23:40:07 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end |