diff --git a/Library/Homebrew/cask/audit.rb b/Library/Homebrew/cask/audit.rb index 3a5fcae495689bce7909bc1b8c82ad3c366f9a76..5e21b2fc21fda4a5e7a510d0510a3c7aec6865f6 100644 --- a/Library/Homebrew/cask/audit.rb +++ b/Library/Homebrew/cask/audit.rb @@ -13,7 +13,7 @@ module Cask attr_reader :cask, :commit_range, :download - attr_predicate :appcast? + attr_predicate :appcast?, :new_cask?, :strict?, :online? def initialize(cask, appcast: false, download: false, quarantine: nil, token_conflicts: false, online: false, strict: false, @@ -34,6 +34,7 @@ module Cask check_required_stanzas check_version check_sha256 + check_desc check_url check_generic_artifacts check_token_valid @@ -279,6 +280,14 @@ module Cask end end + def check_desc + return unless new_cask? + + return if cask.desc.present? + + add_warning "Cask should have a description. Please add a `desc` stanza." + end + def check_url return unless cask.url @@ -339,7 +348,7 @@ module Cask end def check_token_valid - return unless @strict + return unless strict? add_warning "cask token is not lowercase" if cask.token.downcase! @@ -365,7 +374,7 @@ module Cask end def check_token_bad_words - return unless @strict + return unless strict? token = cask.token @@ -467,8 +476,8 @@ module Cask end def get_repo_data(regex) - return unless @online - return unless @new_cask + return unless online? + return unless new_cask? _, user, repo = *regex.match(cask.url.to_s) _, user, repo = *regex.match(cask.homepage) unless user diff --git a/Library/Homebrew/test/cask/audit_spec.rb b/Library/Homebrew/test/cask/audit_spec.rb index fa18a168dcbb712e536d2906034afe093c8eae37..7bcbc3b0a2744c31e77b3e13d95464c9336d2fdd 100644 --- a/Library/Homebrew/test/cask/audit_spec.rb +++ b/Library/Homebrew/test/cask/audit_spec.rb @@ -33,12 +33,14 @@ describe Cask::Audit, :cask do let(:download) { false } let(:token_conflicts) { false } let(:strict) { false } + let(:new_cask) { false } let(:fake_system_command) { class_double(SystemCommand) } let(:audit) { described_class.new(cask, download: download, token_conflicts: token_conflicts, command: fake_system_command, - strict: strict) + strict: strict, + new_cask: new_cask) } describe "#result" do @@ -790,5 +792,58 @@ describe Cask::Audit, :cask do expect(subject).to fail_with(/exception while auditing/) end end + + describe "without description" do + let(:cask_token) { "without-description" } + let(:cask) do + tmp_cask cask_token.to_s, <<~RUBY + cask '#{cask_token}' do + version '1.0' + sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a' + url "https://brew.sh/" + name 'Audit' + homepage 'https://brew.sh/' + app 'Audit.app' + end + RUBY + end + + context "when `new_cask` is true" do + let(:new_cask) { true } + + it "warns" do + expect(subject).to warn_with(/should have a description/) + end + end + + context "when `new_cask` is true" do + let(:new_cask) { false } + + it "does not warn" do + expect(subject).not_to warn_with(/should have a description/) + end + end + end + + context "with description" do + let(:cask_token) { "with-description" } + let(:cask) do + tmp_cask cask_token.to_s, <<~RUBY + cask '#{cask_token}' do + version '1.0' + sha256 '8dd95daa037ac02455435446ec7bc737b34567afe9156af7d20b2a83805c1d8a' + url "https://brew.sh/" + name 'Audit' + desc 'Cask Auditor' + homepage 'https://brew.sh/' + app 'Audit.app' + end + RUBY + end + + it "does not warn" do + expect(subject).not_to warn_with(/should have a description/) + end + end end end