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
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|
problem "#{name}: #{message}"
end
@ -508,7 +511,10 @@ module Homebrew
spec.resources.each_value do |resource|
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|
problem "#{name} resource #{resource.name.inspect}: #{message}"
end
@ -746,11 +752,9 @@ module Homebrew
methods.map(&:to_s).grep(/^audit_/).each do |audit_method_name|
name = audit_method_name.delete_prefix("audit_")
if only_audits
next unless only_audits.include?(name)
elsif except_audits
next if except_audits.include?(name)
end
next if only_audits&.exclude?(name)
next if except_audits&.include?(name)
send(audit_method_name)
end
end

View File

@ -20,14 +20,23 @@ module Homebrew
@spec_name = spec_name
@online = options[:online]
@strict = options[:strict]
@only = options[:only]
@except = options[:except]
@problems = []
end
def audit
audit_version
audit_download_strategy
audit_checksum
audit_urls
only_audits = @only
except_audits = @except
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
end