ResourceAuditor: Allow only/except options

This commit is contained in:
Sam Ford 2021-06-15 09:55:28 -04:00
parent 7eb3c08d20
commit a1cf581118
No known key found for this signature in database
GPG Key ID: 95209E46C7FFDEFE
2 changed files with 24 additions and 11 deletions

View File

@ -500,7 +500,10 @@ module Homebrew
spec_name = name.downcase.to_sym spec_name = name.downcase.to_sym
next unless (spec = formula.send(spec_name)) next unless (spec = formula.send(spec_name))
ra = ResourceAuditor.new(spec, spec_name, online: @online, strict: @strict).audit ra = ResourceAuditor.new(
spec, spec_name,
online: @online, strict: @strict, only: @only, except: @except
).audit
ra.problems.each do |message| ra.problems.each do |message|
problem "#{name}: #{message}" problem "#{name}: #{message}"
end end
@ -508,7 +511,10 @@ module Homebrew
spec.resources.each_value do |resource| spec.resources.each_value do |resource|
problem "Resource name should be different from the formula name" if resource.name == formula.name problem "Resource name should be different from the formula name" if resource.name == formula.name
ra = ResourceAuditor.new(resource, spec_name, online: @online, strict: @strict).audit ra = ResourceAuditor.new(
resource, spec_name,
online: @online, strict: @strict, only: @only, except: @except
).audit
ra.problems.each do |message| ra.problems.each do |message|
problem "#{name} resource #{resource.name.inspect}: #{message}" problem "#{name} resource #{resource.name.inspect}: #{message}"
end end
@ -746,11 +752,9 @@ module Homebrew
methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name| methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name|
name = audit_method_name.delete_prefix("audit_") name = audit_method_name.delete_prefix("audit_")
if only_audits next if only_audits&.exclude?(name)
next unless only_audits.include?(name) next if except_audits&.include?(name)
elsif except_audits
next if except_audits.include?(name)
end
send(audit_method_name) send(audit_method_name)
end end
end end

View File

@ -20,14 +20,23 @@ module Homebrew
@spec_name = spec_name @spec_name = spec_name
@online = options[:online] @online = options[:online]
@strict = options[:strict] @strict = options[:strict]
@only = options[:only]
@except = options[:except]
@problems = [] @problems = []
end end
def audit def audit
audit_version only_audits = @only
audit_download_strategy except_audits = @except
audit_checksum
audit_urls methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name|
name = audit_method_name.delete_prefix("audit_")
next if only_audits&.exclude?(name)
next if except_audits&.include?(name)
send(audit_method_name)
end
self self
end end