| 
									
										
										
										
											2020-10-10 14:16:11 +02:00
										 |  |  | # typed: false | 
					
						
							| 
									
										
										
										
											2019-04-19 15:38:03 +09:00
										 |  |  | # frozen_string_literal: true | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-10-26 19:41:14 +01:00
										 |  |  | require "rubocops/lines" | 
					
						
							| 
									
										
										
										
											2017-07-29 16:36:32 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::FormulaAudit::Lines do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |   context "when auditing deprecated special dependencies" do | 
					
						
							|  |  |  |     it "reports an offense when using depends_on :automake" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           depends_on :automake | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^^^^^ :automake is deprecated. Usage should be \"automake\".
 | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-07-29 16:36:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when using depends_on :autoconf" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           depends_on :autoconf | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^^^^^ :autoconf is deprecated. Usage should be \"autoconf\".
 | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-07-29 16:36:32 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when using depends_on :libtool" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           depends_on :libtool | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^^^^ :libtool is deprecated. Usage should be \"libtool\".
 | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when using depends_on :apr" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           depends_on :apr | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^ :apr is deprecated. Usage should be \"apr-util\".
 | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when using depends_on :tex" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           depends_on :tex | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^ :tex is deprecated. | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-07-29 16:36:32 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::FormulaAudit::ClassInheritance do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing formula class inheritance" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when not using spaces for class inheritance" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY, "/homebrew-core/Formula/foo.rb") | 
					
						
							|  |  |  |         class Foo<Formula | 
					
						
							|  |  |  |                   ^^^^^^^ Use a space in class inheritance: class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::FormulaAudit::Comments do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing comment text" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when commented cmake calls exist" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |           # system "cmake", ".", *std_cmake_args | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Please remove default template comments | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when default template comments exist" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           # PLEASE REMOVE | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^ Please remove default template comments | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `depends_on` is commented" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |           # depends_on "foo" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^ Commented-out dependency "foo" | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-01-08 14:55:31 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense if citation tags are present" do | 
					
						
							| 
									
										
										
										
											2020-01-08 14:55:31 -05:00
										 |  |  |       expect_offense(<<~RUBY, "/homebrew-core/") | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           # cite Howell_2009: | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should not use `cite` comments | 
					
						
							|  |  |  |           # doi "10.111/222.x" | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should not use `doi` comments | 
					
						
							|  |  |  |           # tag "software" | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^ Formulae in homebrew/core should not use `tag` comments | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  | describe RuboCop::Cop::FormulaAudit::AssertStatements do | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing formula assertions" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when assert ... include is used" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           assert File.read("inbox").include?("Sample message 1") | 
					
						
							|  |  |  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `assert_match` instead of `assert ...include?` | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when assert ... exist? is used without a negation" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           assert File.exist? "default.ini" | 
					
						
							|  |  |  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^ Use `assert_predicate <path_to_file>, :exist?` instead of `assert File.exist? "default.ini"` | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when assert ... exist? is used with a negation" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           assert !File.exist?("default.ini") | 
					
						
							|  |  |  |                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^ Use `refute_predicate <path_to_file>, :exist?` instead of `assert !File.exist?("default.ini")` | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when assert ... executable? is used without a negation" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           assert File.executable? f | 
					
						
							|  |  |  |                  ^^^^^^^^^^^^^^^^^^ Use `assert_predicate <path_to_file>, :executable?` instead of `assert File.executable? f` | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  | describe RuboCop::Cop::FormulaAudit::OptionDeclarations do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing options" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.without?` is used in homebrew/core" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY, "/homebrew-core/") | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             build.without? "bar" | 
					
						
							|  |  |  |             ^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should not use `build.without?`. | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2020-01-09 10:09:55 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-01-09 10:09:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.with?` is used in homebrew/core" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY, "/homebrew-core/") | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             build.with? "bar" | 
					
						
							|  |  |  |             ^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should not use `build.with?`. | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2020-01-09 10:09:55 -05:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-01-09 10:09:55 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.without?` is used for a conditional dependency" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "bar" if build.without?("baz") | 
					
						
							|  |  |  |                               ^^^^^^^^^^^^^^^^^^^^^ Use `:optional` or `:recommended` instead of `if build.without?("baz")` | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-05 23:43:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.without?` is used for a conditional dependency" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "bar" if build.with?("baz") | 
					
						
							|  |  |  |                               ^^^^^^^^^^^^^^^^^^ Use `:optional` or `:recommended` instead of `if build.with?("baz")` | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-05 23:43:09 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.without?` is used with `unless`" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def post_install | 
					
						
							|  |  |  |             return unless build.without? "bar" | 
					
						
							|  |  |  |                           ^^^^^^^^^^^^^^^^^^^^ Use if build.with? "bar" instead of unless build.without? "bar" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.with?` is used with `unless`" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def post_install | 
					
						
							|  |  |  |             return unless build.with? "bar" | 
					
						
							|  |  |  |                           ^^^^^^^^^^^^^^^^^ Use if build.without? "bar" instead of unless build.with? "bar" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.with?` is negated" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def post_install | 
					
						
							|  |  |  |             return if !build.with? "bar" | 
					
						
							|  |  |  |                       ^^^^^^^^^^^^^^^^^^ Don't negate 'build.with?': use 'build.without?' | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.without?` is negated" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def post_install | 
					
						
							|  |  |  |             return if !build.without? "bar" | 
					
						
							|  |  |  |                       ^^^^^^^^^^^^^^^^^^^^^ Don't negate 'build.without?': use 'build.with?' | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when a `build.without?` conditional is unnecessary" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def post_install | 
					
						
							|  |  |  |             return if build.without? "--without-bar" | 
					
						
							|  |  |  |                                      ^^^^^^^^^^^^^^^ Don't duplicate 'without': Use `build.without? \"bar\"` to check for \"--without-bar\"
 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when a `build.with?` conditional is unnecessary" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def post_install | 
					
						
							|  |  |  |             return if build.with? "--with-bar" | 
					
						
							|  |  |  |                                   ^^^^^^^^^^^^ Don't duplicate 'with': Use `build.with? \"bar\"` to check for \"--with-bar\"
 | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-09-10 18:55:01 +00:00
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-09-10 18:55:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.include?` is used" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           def post_install | 
					
						
							|  |  |  |             return if build.include? "foo" | 
					
						
							|  |  |  |                       ^^^^^^^^^^^^^^^^^^^^ `build.include?` is deprecated | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `def option` is used" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |           def options | 
					
						
							|  |  |  |           ^^^^^^^^^^^ Use new-style option definitions | 
					
						
							|  |  |  |             [["--bar", "desc"]] | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-06-06 11:31:07 -04:00
										 |  |  | describe RuboCop::Cop::FormulaAudit::MpiCheck do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |   context "when auditing MPI dependencies" do | 
					
						
							|  |  |  |     it "reports and corrects an offense when using depends_on \"mpich\" in homebrew/core" do | 
					
						
							| 
									
										
										
										
											2019-06-06 11:31:07 -04:00
										 |  |  |       expect_offense(<<~RUBY, "/homebrew-core/") | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           depends_on "mpich" | 
					
						
							| 
									
										
										
										
											2020-01-08 15:38:48 -05:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core should use 'depends_on "open-mpi"' instead of 'depends_on "mpich"'. | 
					
						
							| 
									
										
										
										
											2019-06-06 11:31:07 -04:00
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2019-06-06 16:27:53 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |       expect_correction(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           depends_on "open-mpi" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2019-06-06 11:31:07 -04:00
										 |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  | describe RuboCop::Cop::FormulaAudit::SafePopenCommands do | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |   context "when auditing popen commands" do | 
					
						
							|  |  |  |     it "reports and corrects `Utils.popen_read` usage" do | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             Utils.popen_read "foo" | 
					
						
							|  |  |  |             ^^^^^^^^^^^^^^^^^^^^^^ Use `Utils.safe_popen_read` instead of `Utils.popen_read` | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             Utils.safe_popen_read "foo" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects `Utils.popen_write` usage" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             Utils.popen_write "foo" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             ^^^^^^^^^^^^^^^^^^^^^^^ Use `Utils.safe_popen_write` instead of `Utils.popen_write` | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             Utils.safe_popen_write "foo" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "does not report an offense when `Utils.popen_read` is used in a test block" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install; end | 
					
						
							|  |  |  |           test do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read "foo" | 
					
						
							| 
									
										
										
										
											2020-06-04 21:05:38 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  | describe RuboCop::Cop::FormulaAudit::ShellVariables do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing shell variables" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects unexpanded shell variables in `Utils.popen`" do | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             Utils.popen "SHELL=bash foo" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                         ^^^^^^^^^^^^^^^^ Use `Utils.popen({ "SHELL" => "bash" }, "foo")` instead of `Utils.popen "SHELL=bash foo"` | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen { "SHELL" => "bash" }, "foo" | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects unexpanded shell variables in `Utils.safe_popen_read`" do | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_read "SHELL=bash foo" | 
					
						
							|  |  |  |                                   ^^^^^^^^^^^^^^^^ Use `Utils.safe_popen_read({ "SHELL" => "bash" }, "foo")` instead of `Utils.safe_popen_read "SHELL=bash foo"` | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_read { "SHELL" => "bash" }, "foo" | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects unexpanded shell variables in `Utils.safe_popen_write`" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_write "SHELL=bash foo" | 
					
						
							|  |  |  |                                    ^^^^^^^^^^^^^^^^ Use `Utils.safe_popen_write({ "SHELL" => "bash" }, "foo")` instead of `Utils.safe_popen_write "SHELL=bash foo"` | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_write { "SHELL" => "bash" }, "foo" | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects unexpanded shell variables while preserving string interpolation" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen "SHELL=bash \#{bin}/foo" | 
					
						
							|  |  |  |                         ^^^^^^^^^^^^^^^^^^^^^^^ Use `Utils.popen({ "SHELL" => "bash" }, "\#{bin}/foo")` instead of `Utils.popen "SHELL=bash \#{bin}/foo"` | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen { "SHELL" => "bash" }, "\#{bin}/foo" | 
					
						
							| 
									
										
										
										
											2020-06-04 21:52:20 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 10:58:36 -04:00
										 |  |  | describe RuboCop::Cop::FormulaAudit::LicenseArrays do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing license arrays" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for license strings" do | 
					
						
							| 
									
										
										
										
											2020-08-20 10:58:36 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license "MIT" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for license symbols" do | 
					
						
							| 
									
										
										
										
											2020-08-20 10:58:36 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license :public_domain | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for license hashes" do | 
					
						
							| 
									
										
										
										
											2020-08-20 10:58:36 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license any_of: ["MIT", "0BSD"] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects use of a license array" do | 
					
						
							| 
									
										
										
										
											2020-08-20 10:58:36 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license ["MIT", "0BSD"] | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^ Use `license any_of: ["MIT", "0BSD"]` instead of `license ["MIT", "0BSD"]` | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-08-20 10:58:36 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license any_of: ["MIT", "0BSD"] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-08-20 11:20:04 -04:00
										 |  |  | describe RuboCop::Cop::FormulaAudit::Licenses do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing licenses" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for license strings" do | 
					
						
							| 
									
										
										
										
											2020-08-20 11:20:04 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license "MIT" | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for license symbols" do | 
					
						
							| 
									
										
										
										
											2020-08-20 11:20:04 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license :public_domain | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for license hashes" do | 
					
						
							| 
									
										
										
										
											2020-08-20 11:20:04 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license any_of: ["MIT", "0BSD"] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for license exceptions" do | 
					
						
							| 
									
										
										
										
											2020-10-05 16:23:52 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license "MIT" => { with: "LLVM-exception" } | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for multiline nested license hashes" do | 
					
						
							| 
									
										
										
										
											2020-08-20 11:20:04 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license any_of: [ | 
					
						
							|  |  |  |             "MIT", | 
					
						
							|  |  |  |             all_of: ["0BSD", "Zlib"], | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for multiline nested license hashes with exceptions" do | 
					
						
							| 
									
										
										
										
											2020-10-05 16:23:52 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license any_of: [ | 
					
						
							|  |  |  |             "MIT", | 
					
						
							|  |  |  |             all_of: ["0BSD", "Zlib"], | 
					
						
							|  |  |  |             "GPL-2.0-only" => { with: "LLVM-exception" }, | 
					
						
							|  |  |  |           ] | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense for nested license hashes on a single line" do | 
					
						
							| 
									
										
										
										
											2020-08-20 11:20:04 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							|  |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |           license any_of: ["MIT", all_of: ["0BSD", "Zlib"]] | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Split nested license declarations onto multiple lines | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  | describe RuboCop::Cop::FormulaAudit::PythonVersions do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing Python versions" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for Python with no dependency" do | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python@3.8" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for unversioned Python references" do | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses for Python with no version" do | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python3" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when a Python reference matches its dependency" do | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python@3.9" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |     it "reports no offenses when a Python reference matches its dependency without `@`" do | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python3.9" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when a Python reference matches its two-digit dependency" do | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.10" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python@3.10" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when a Python reference matches its two-digit dependency without `@`" do | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.10" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python3.10" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects Python references with mismatched versions" do | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python@3.8" | 
					
						
							|  |  |  |                  ^^^^^^^^^^^^ References to `python@3.8` should match the specified python dependency (`python@3.9`) | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python@3.9" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects Python references with mismatched versions without `@`" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python3.8" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                  ^^^^^^^^^^^ References to `python3.8` should match the specified python dependency (`python3.9`) | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.9" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python3.9" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects Python references with mismatched two-digit versions" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |           depends_on "python@3.11" | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             puts "python@3.10" | 
					
						
							|  |  |  |                  ^^^^^^^^^^^^^ References to `python@3.10` should match the specified python dependency (`python@3.11`) | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |           depends_on "python@3.11" | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             puts "python@3.11" | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects Python references with mismatched two-digit versions without `@`" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.11" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python3.10" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                  ^^^^^^^^^^^^ References to `python3.10` should match the specified python dependency (`python3.11`) | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-10-11 09:46:14 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           depends_on "python@3.11" | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             puts "python3.11" | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-10-10 13:38:43 -04:00
										 |  |  |   end | 
					
						
							|  |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  | describe RuboCop::Cop::FormulaAudit::Miscellaneous do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							| 
									
										
										
										
											2017-09-10 18:55:01 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing formula miscellany" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense for unneeded `FileUtils` usage" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           FileUtils.mv "hello" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^ Don\'t need \'FileUtils.\' before mv | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-05 14:58:09 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-12 23:28:08 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense for long `inreplace` block variable names" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-12 23:28:08 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           inreplace "foo" do |longvar| | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ \"inreplace <filenames> do |s|\" is preferred over \"|longvar|\".
 | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |             somerandomCall(longvar) | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-12 23:28:08 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense for invalid `rebuild` numbers" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           bottle do | 
					
						
							|  |  |  |             rebuild 0
 | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |             ^^^^^^^^^ 'rebuild 0' should be removed | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |             sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `OS.linux?` is used in homebrew/core" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY, "/homebrew-core/") | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           bottle do | 
					
						
							|  |  |  |             if OS.linux? | 
					
						
							| 
									
										
										
										
											2020-01-08 15:38:48 -05:00
										 |  |  |                ^^^^^^^^^ Don\'t use OS.linux?; homebrew/core only supports macOS | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |               nil | 
					
						
							|  |  |  |             end | 
					
						
							|  |  |  |             sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when a useless `fails_with :llvm` is used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           bottle do | 
					
						
							|  |  |  |             sha256 "fe0679b932dd43a87fd415b609a7fbac7a069d117642ae8ebaac46ae1fb9f0b3" => :sierra | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |           fails_with :llvm do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^ 'fails_with :llvm' is now a no-op so should be removed | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |             build 2335
 | 
					
						
							|  |  |  |             cause "foo" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-10-21 01:39:04 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-12 23:28:08 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `def test` is used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-12 23:28:08 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  | 
 | 
					
						
							|  |  |  |           def test | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^ Use new-style test definitions (test do) | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |             assert_equals "1", "1" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-12 23:28:08 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-13 14:50:29 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-12 00:29:19 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `skip_clean` is used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-13 14:50:29 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           skip_clean :all | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^ `skip_clean :all` is deprecated; brew no longer strips symbols. Pass explicit paths to prevent Homebrew from removing empty folders. | 
					
						
							| 
									
										
										
										
											2017-08-13 14:50:29 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-12 23:28:08 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 00:02:44 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.universal?` is used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 00:02:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           if build.universal? | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |              ^^^^^^^^^^^^^^^^ macOS has been 64-bit only since 10.6 so build.universal? is deprecated. | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |              "foo" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-14 00:02:44 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 01:09:06 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-12 00:29:19 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when `build.universal?` is used in an exempt formula" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/wine.rb") | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |         class Wine < Formula | 
					
						
							| 
									
										
										
										
											2017-08-14 01:09:06 +05:30
										 |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           if build.universal? | 
					
						
							|  |  |  |              "foo" | 
					
						
							|  |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-14 01:09:06 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 01:25:44 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-12 00:29:19 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `ENV.universal_binary` is used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 01:25:44 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           if build? | 
					
						
							|  |  |  |              ENV.universal_binary | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |              ^^^^^^^^^^^^^^^^^^^^ macOS has been 64-bit only since 10.6 so ENV.universal_binary is deprecated. | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           end | 
					
						
							| 
									
										
										
										
											2017-08-14 01:25:44 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 00:02:44 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 01:52:48 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when `ENV.universal_binary` is used in an exempt formula" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/wine.rb") | 
					
						
							| 
									
										
										
										
											2017-10-08 21:46:32 -04:00
										 |  |  |         class Wine < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-08 21:46:32 -04:00
										 |  |  |           if build? | 
					
						
							| 
									
										
										
										
											2017-10-21 13:26:25 +05:30
										 |  |  |             ENV.universal_binary | 
					
						
							| 
									
										
										
										
											2017-10-08 21:46:32 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-10-08 21:46:32 -04:00
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `install_name_tool` is called" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 01:55:47 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           system "install_name_tool", "-id" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                  ^^^^^^^^^^^^^^^^^^^ Use ruby-macho instead of calling "install_name_tool" | 
					
						
							| 
									
										
										
										
											2017-08-14 01:55:47 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 01:55:47 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 02:14:20 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `npm install` is called without Language::Node arguments" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 02:14:20 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           system "npm", "install" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^^^^^^^^^ Use Language::Node for npm install args | 
					
						
							| 
									
										
										
										
											2017-08-14 02:14:20 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 02:14:20 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 02:18:46 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when `npm install` is called without Language::Node arguments in an exempt formula" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_no_offenses(<<~RUBY, "/homebrew-core/Formula/kibana@4.4.rb") | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |         class KibanaAT44 < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           system "npm", "install" | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `depends_on` is called with an instance" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 02:18:46 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           depends_on FOO::BAR.new | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |                      ^^^^^^^^^^^^ `depends_on` can take requirement classes instead of instances | 
					
						
							| 
									
										
										
										
											2017-08-14 02:18:46 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 02:18:46 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 02:32:29 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `Dir` is called without a globbing argument" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 02:43:54 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           rm_rf Dir["src/{llvm,test,librustdoc,etc/snapshot.pyc}"] | 
					
						
							|  |  |  |           rm_rf Dir["src/snapshot.pyc"] | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                     ^^^^^^^^^^^^^^^^^^ Dir(["src/snapshot.pyc"]) is unnecessary; just use "src/snapshot.pyc" | 
					
						
							| 
									
										
										
										
											2017-08-14 02:43:54 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 02:43:54 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 02:47:29 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when executing a system command for which there is a Ruby FileUtils equivalent" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 02:47:29 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |           system "mkdir", "foo" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                  ^^^^^^^ Use the `mkdir` Ruby method instead of `system "mkdir", "foo"` | 
					
						
							| 
									
										
										
										
											2017-08-14 02:47:29 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 02:47:29 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 02:49:52 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when top-level functions are defined outside of a class body" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |         def test | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |         ^^^^^^^^ Define method test in the class body, not at the top-level | 
					
						
							| 
									
										
										
										
											2017-10-21 12:50:49 +05:30
										 |  |  |            nil | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-08-14 02:49:52 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 02:49:52 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 02:49:52 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 15:22:44 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it 'reports an offense when `man+"man8"` is used' do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 15:41:03 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |           def install | 
					
						
							| 
									
										
										
										
											2017-08-14 15:41:03 +05:30
										 |  |  |             man1.install man+"man8" => "faad.1" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                              ^^^^^^ "man+"man8"" should be "man8" | 
					
						
							| 
									
										
										
										
											2017-08-14 15:41:03 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 15:41:03 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when a hard-coded `gcc` is referenced" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~'RUBY') | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |           def install | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |             system "/usr/bin/gcc", "foo" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                    ^^^^^^^^^^^^^^ Use "#{ENV.cc}" instead of hard-coding "gcc" | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when a hard-coded `g++` is referenced" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~'RUBY') | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |           def install | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |             system "/usr/bin/g++", "-o", "foo", "foo.cc" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                    ^^^^^^^^^^^^^^ Use "#{ENV.cxx}" instead of hard-coding "g++" | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 19:58:39 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when a hard-coded `llvm-g++` is set as COMPILER_PATH" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~'RUBY') | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |           def install | 
					
						
							|  |  |  |             ENV["COMPILER_PATH"] = "/usr/bin/llvm-g++" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                                    ^^^^^^^^^^^^^^^^^^^ Use "#{ENV.cxx}" instead of hard-coding "llvm-g++" | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when a hard-coded `gcc` is set as COMPILER_PATH" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |           def install | 
					
						
							|  |  |  |             ENV["COMPILER_PATH"] = "/usr/bin/gcc" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                                    ^^^^^^^^^^^^^^ Use \"\#{ENV.cc}\" instead of hard-coding \"gcc\"
 | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 20:10:45 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 21:34:01 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when the formula path shortcut `man` could be used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~'RUBY') | 
					
						
							| 
									
										
										
										
											2017-08-14 21:34:01 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 21:34:01 +05:30
										 |  |  |           def install | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |             mv "#{share}/man", share | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                         ^^^^ "#{share}/man" should be "#{man}" | 
					
						
							| 
									
										
										
										
											2017-08-14 21:34:01 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 21:34:01 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when the formula path shortcut `libexec` could be used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~'RUBY') | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |           def install | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |             mv "#{prefix}/libexec", share | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                          ^^^^^^^^ "#{prefix}/libexec" should be "#{libexec}" | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when the formula path shortcut `info` could be used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~'RUBY') | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |           def install | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |             system "./configure", "--INFODIR=#{prefix}/share/info" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                                                       ^^^^^^^^^^^ "#{prefix}/share/info" should be "#{info}" | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-10-12 00:29:19 +05:30
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when the formula path shortcut `man8` could be used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~'RUBY') | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |           def install | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |             system "./configure", "--MANDIR=#{prefix}/share/man/man8" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                                                      ^^^^^^^^^^^^^^^ "#{prefix}/share/man/man8" should be "#{man8}" | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 22:44:28 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when unvendored lua modules are used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 23:05:00 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 23:05:00 +05:30
										 |  |  |           depends_on "lpeg" => :lua51 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                                ^^^^^^ lua modules should be vendored rather than use deprecated `depends_on \"lpeg\" => :lua51` | 
					
						
							| 
									
										
										
										
											2017-08-14 23:05:00 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 23:05:00 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `export` is used to set environment variables" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-14 23:32:06 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-14 23:32:06 +05:30
										 |  |  |           system "export", "var=value" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                  ^^^^^^^^ Use ENV instead of invoking 'export' to modify the environment | 
					
						
							| 
									
										
										
										
											2017-08-14 23:32:06 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-14 23:32:06 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when dependencies with invalid options are used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:05:50 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-15 00:05:50 +05:30
										 |  |  |           depends_on "foo" => "with-bar" | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                               ^^^^^^^^^^ Dependency foo should not use option with-bar | 
					
						
							| 
									
										
										
										
											2018-05-05 21:11:16 +05:30
										 |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when dependencies with invalid options are used in an array" do | 
					
						
							| 
									
										
										
										
											2018-05-05 21:11:16 +05:30
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2018-05-05 21:11:16 +05:30
										 |  |  |           depends_on "httpd" => [:build, :test] | 
					
						
							|  |  |  |           depends_on "foo" => [:optional, "with-bar"] | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                                           ^^^^^^^^^^ Dependency foo should not use option with-bar | 
					
						
							| 
									
										
										
										
											2018-05-05 21:11:16 +05:30
										 |  |  |           depends_on "icu4c" => [:optional, "c++11"] | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |                                             ^^^^^^^ Dependency icu4c should not use option c++11
 | 
					
						
							| 
									
										
										
										
											2017-08-15 00:05:50 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-15 00:05:50 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.head?` could be used instead of checking `version`" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:29:58 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-15 00:29:58 +05:30
										 |  |  |           if version == "HEAD" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |              ^^^^^^^^^^^^^^^^^ Use 'build.head?' instead of inspecting 'version' | 
					
						
							| 
									
										
										
										
											2017-08-15 00:29:58 +05:30
										 |  |  |             foo() | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-15 00:29:58 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `ARGV.include? (--HEAD)` is used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:36:37 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-15 00:36:37 +05:30
										 |  |  |           test do | 
					
						
							|  |  |  |             head = ARGV.include? "--HEAD" | 
					
						
							| 
									
										
										
										
											2017-12-02 17:03:11 +05:30
										 |  |  |                    ^^^^ Use build instead of ARGV to check options | 
					
						
							| 
									
										
										
										
											2021-01-05 15:22:26 -08:00
										 |  |  |                    ^^^^^^^^^^^^^^^^^^^^^^ Use "if build.head?" instead | 
					
						
							| 
									
										
										
										
											2017-08-15 00:36:37 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-15 00:36:37 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `needs :openmp` is used" do | 
					
						
							| 
									
										
										
										
											2017-12-30 19:15:52 +00:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-12-30 19:15:52 +00:00
										 |  |  |           needs :openmp | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^ 'needs :openmp' should be replaced with 'depends_on \"gcc\"' | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `MACOS_VERSION` is used" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-15 00:42:56 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-15 00:42:56 +05:30
										 |  |  |           test do | 
					
						
							|  |  |  |             version = MACOS_VERSION | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |                       ^^^^^^^^^^^^^ Use MacOS.version instead of MACOS_VERSION | 
					
						
							| 
									
										
										
										
											2017-08-15 00:42:56 +05:30
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-15 00:42:56 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.with?` is used for a conditional dependency" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-10-29 23:40:04 +05:30
										 |  |  |           depends_on "foo" if build.with? "foo" | 
					
						
							|  |  |  |           ^^^^^^^^^^^^^^^^ Replace depends_on "foo" if build.with? "foo" with depends_on "foo" => :optional | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.without?` is used for a negated conditional dependency" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |           depends_on :foo unless build.without? "foo" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^ Replace depends_on :foo unless build.without? "foo" with depends_on :foo => :recommended | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports an offense when `build.include?` is used for a negated conditional dependency" do | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           desc "foo" | 
					
						
							| 
									
										
										
										
											2018-11-28 20:51:55 +01:00
										 |  |  |           url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |           depends_on :foo unless build.include? "without-foo" | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |           ^^^^^^^^^^^^^^^ Replace depends_on :foo unless build.include? "without-foo" with depends_on :foo => :recommended | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |         end | 
					
						
							| 
									
										
										
										
											2017-10-21 03:12:50 +02:00
										 |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2017-08-15 16:09:32 +05:30
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-04-13 14:35:38 +01:00
										 |  |  | end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::FormulaAuditStrict::MakeCheck do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-03 14:30:34 -05:00
										 |  |  |   let(:path) { Tap::TAP_DIRECTORY/"homebrew/homebrew-core" } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   before do | 
					
						
							|  |  |  |     path.mkpath | 
					
						
							|  |  |  |     (path/"style_exceptions").mkpath | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   def setup_style_exceptions | 
					
						
							|  |  |  |     (path/"style_exceptions/make_check_allowlist.json").write <<~JSON | 
					
						
							|  |  |  |       [ "bar" ] | 
					
						
							|  |  |  |     JSON | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |   it "reports an offense when formulae in homebrew/core run build-time checks" do | 
					
						
							| 
									
										
										
										
											2020-12-03 14:30:34 -05:00
										 |  |  |     setup_style_exceptions | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_offense(<<~RUBY, "#{path}/Formula/foo.rb") | 
					
						
							| 
									
										
										
										
											2020-04-13 14:35:38 +01:00
										 |  |  |       class Foo < Formula | 
					
						
							|  |  |  |         desc "foo" | 
					
						
							|  |  |  |         url 'https://brew.sh/foo-1.0.tgz' | 
					
						
							|  |  |  |         system "make", "-j1", "test" | 
					
						
							|  |  |  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Formulae in homebrew/core (except e.g. cryptography, libraries) should not run build-time checks | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2020-12-03 14:30:34 -05:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |   it "reports no offenses when exempted formulae in homebrew/core run build-time checks" do | 
					
						
							| 
									
										
										
										
											2020-12-03 14:30:34 -05:00
										 |  |  |     setup_style_exceptions | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     expect_no_offenses(<<~RUBY, "#{path}/Formula/bar.rb") | 
					
						
							|  |  |  |       class Bar < Formula | 
					
						
							|  |  |  |         desc "bar" | 
					
						
							|  |  |  |         url 'https://brew.sh/bar-1.0.tgz' | 
					
						
							|  |  |  |         system "make", "-j1", "test" | 
					
						
							|  |  |  |       end | 
					
						
							|  |  |  |     RUBY | 
					
						
							|  |  |  |   end | 
					
						
							| 
									
										
										
										
											2017-08-02 23:49:51 +05:30
										 |  |  | end | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | describe RuboCop::Cop::FormulaAuditStrict::ShellCommands do | 
					
						
							|  |  |  |   subject(:cop) { described_class.new } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-14 18:55:31 -08:00
										 |  |  |   context "when auditing shell commands" do | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `system` arguments should be separated" do | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							|  |  |  |             system "foo bar" | 
					
						
							|  |  |  |                    ^^^^^^^^^ Separate `system` commands into `\"foo\", \"bar\"` | 
					
						
							|  |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             system "foo", "bar" | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `system` arguments with string interpolation should be separated" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             system "\#{bin}/foo bar" | 
					
						
							|  |  |  |                    ^^^^^^^^^^^^^^^^ Separate `system` commands into `\"\#{bin}/foo\", \"bar\"` | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             system "\#{bin}/foo", "bar" | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when `system` with metacharacter arguments are called" do | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             system "foo bar > baz" | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when trailing arguments to `system` are unseparated" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             system "foo", "bar baz" | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when `Utils.popen` arguments are unseparated" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen("foo bar") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `Utils.popen_read` arguments are unseparated" do | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read("foo bar") | 
					
						
							|  |  |  |                              ^^^^^^^^^ Separate `Utils.popen_read` commands into `\"foo\", \"bar\"` | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read("foo", "bar") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `Utils.safe_popen_read` arguments are unseparated" do | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_read("foo bar") | 
					
						
							|  |  |  |                                   ^^^^^^^^^ Separate `Utils.safe_popen_read` commands into `\"foo\", \"bar\"` | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_read("foo", "bar") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `Utils.popen_write` arguments are unseparated" do | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |       expect_offense(<<~RUBY) | 
					
						
							|  |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_write("foo bar") | 
					
						
							|  |  |  |                               ^^^^^^^^^ Separate `Utils.popen_write` commands into `\"foo\", \"bar\"` | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_write("foo", "bar") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `Utils.safe_popen_write` arguments are unseparated" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_write("foo bar") | 
					
						
							|  |  |  |                                    ^^^^^^^^^ Separate `Utils.safe_popen_write` commands into `\"foo\", \"bar\"` | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.safe_popen_write("foo", "bar") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `Utils.popen_read` arguments with interpolation are unseparated" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read("\#{bin}/foo bar") | 
					
						
							|  |  |  |                              ^^^^^^^^^^^^^^^^ Separate `Utils.popen_read` commands into `\"\#{bin}/foo\", \"bar\"` | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read("\#{bin}/foo", "bar") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when `Utils.popen_read` arguments with metacharacters are unseparated" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read("foo bar > baz") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     end | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports no offenses when trailing arguments to `Utils.popen_read` are unseparated" do | 
					
						
							|  |  |  |       expect_no_offenses(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read("foo", "bar baz") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |     it "reports and corrects an offense when `Utils.popen_read` arguments are unseparated after a shell variable" do | 
					
						
							|  |  |  |       expect_offense(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read({ "SHELL" => "bash"}, "foo bar") | 
					
						
							|  |  |  |                                                    ^^^^^^^^^ Separate `Utils.popen_read` commands into `\"foo\", \"bar\"` | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |       expect_correction(<<~RUBY) | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |         class Foo < Formula | 
					
						
							|  |  |  |           def install | 
					
						
							| 
									
										
										
										
											2021-01-12 02:21:51 +11:00
										 |  |  |             Utils.popen_read({ "SHELL" => "bash"}, "foo", "bar") | 
					
						
							| 
									
										
										
										
											2020-07-05 13:57:49 -04:00
										 |  |  |           end | 
					
						
							|  |  |  |         end | 
					
						
							|  |  |  |       RUBY | 
					
						
							|  |  |  |     end | 
					
						
							|  |  |  |   end | 
					
						
							|  |  |  | end |