From c081b3d97581bb1f4fa0541a3d41f0fd2fcf428c Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 2 May 2017 19:03:03 +0100 Subject: [PATCH 1/4] caveats: chomp keg_only reason --- Library/Homebrew/caveats.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/caveats.rb b/Library/Homebrew/caveats.rb index 2032e9ff1a..ee09063fd9 100644 --- a/Library/Homebrew/caveats.rb +++ b/Library/Homebrew/caveats.rb @@ -46,7 +46,7 @@ class Caveats s = <<-EOS.undent This formula is keg-only, which means it was not symlinked into #{HOMEBREW_PREFIX}, - because #{f.keg_only_reason}. + because #{f.keg_only_reason.to_s.chomp}. EOS if f.bin.directory? || f.sbin.directory? s << "\nIf you need to have this software first in your PATH run:\n" From 80483c0206b482cc10756cd73aa0b058d2329393 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 2 May 2017 19:05:56 +0100 Subject: [PATCH 2/4] audit: whitelist 'Firefox' in keg_only_style --- Library/Homebrew/dev-cmd/audit.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index be53e1d6fd..9b0deb7d5e 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -502,6 +502,7 @@ class FormulaAuditor GPG GNOME BSD + Firefox ].freeze reason = formula.keg_only_reason.to_s From 9aeb8f0f0b131919b187f4835a057e4fa4afca82 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 2 May 2017 19:30:41 +0100 Subject: [PATCH 3/4] audit: match start of string, not line --- Library/Homebrew/dev-cmd/audit.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index 9b0deb7d5e..1081fa0ba5 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -511,7 +511,7 @@ class FormulaAuditor reason.sub!(name, "") first_word = reason.split[0] - if reason =~ /^[A-Z]/ && !reason.start_with?(*whitelist) + if reason =~ /\A[A-Z]/ && !reason.start_with?(*whitelist) problem <<-EOS.undent '#{first_word}' from the keg_only reason should be '#{first_word.downcase}'. EOS From bf491e5102f52847ba93aad0dc0f2976f86395d6 Mon Sep 17 00:00:00 2001 From: Dominyk Tiller Date: Tue, 2 May 2017 20:08:30 +0100 Subject: [PATCH 4/4] audit_spec: add keg_only_style tests --- Library/Homebrew/test/dev-cmd/audit_spec.rb | 63 +++++++++++++++++++++ 1 file changed, 63 insertions(+) diff --git a/Library/Homebrew/test/dev-cmd/audit_spec.rb b/Library/Homebrew/test/dev-cmd/audit_spec.rb index 771e1ee799..c914a9a201 100644 --- a/Library/Homebrew/test/dev-cmd/audit_spec.rb +++ b/Library/Homebrew/test/dev-cmd/audit_spec.rb @@ -322,6 +322,69 @@ describe FormulaAuditor do .to eq(["Don't recommend setuid in the caveats, suggest sudo instead."]) end + describe "#audit_keg_only_style" do + specify "keg_only_needs_downcasing" do + fa = formula_auditor "foo", <<-EOS.undent, strict: true + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + + keg_only "Because why not" + end + EOS + + fa.audit_keg_only_style + expect(fa.problems) + .to eq(["'Because' from the keg_only reason should be 'because'.\n"]) + end + + specify "keg_only_redundant_period" do + fa = formula_auditor "foo", <<-EOS.undent, strict: true + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + + keg_only "because this line ends in a period." + end + EOS + + fa.audit_keg_only_style + expect(fa.problems) + .to eq(["keg_only reason should not end with a period."]) + end + + specify "keg_only_handles_block_correctly" do + fa = formula_auditor "foo", <<-EOS.undent, strict: true + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + + keg_only <<-EOF.undent + this line starts with a lowercase word. + + This line does not but that shouldn't be a + problem + EOF + end + EOS + + fa.audit_keg_only_style + expect(fa.problems) + .to eq([]) + end + + specify "keg_only_handles_whitelist_correctly" do + fa = formula_auditor "foo", <<-EOS.undent, strict: true + class Foo < Formula + url "http://example.com/foo-1.0.tgz" + + keg_only "Apple ships foo in the CLT package" + end + EOS + + fa.audit_keg_only_style + expect(fa.problems) + .to eq([]) + end + end + describe "#audit_homepage" do specify "homepage URLs" do fa = formula_auditor "foo", <<-EOS.undent, online: true