From 2a941ec6b17bcb0d9557cf3604d64a3954cc199e Mon Sep 17 00:00:00 2001 From: Rylan Polster Date: Thu, 5 Nov 2020 16:09:54 -0500 Subject: [PATCH] audit, tap: incorporate suggestions from code review --- Library/Homebrew/dev-cmd/audit.rb | 19 +++++++++---------- Library/Homebrew/tap.rb | 8 ++++---- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/Library/Homebrew/dev-cmd/audit.rb b/Library/Homebrew/dev-cmd/audit.rb index cd3046c597..cee7a36767 100644 --- a/Library/Homebrew/dev-cmd/audit.rb +++ b/Library/Homebrew/dev-cmd/audit.rb @@ -121,7 +121,7 @@ module Homebrew # Run tap audits first if args.tap tap = Tap.fetch(args.tap) - ta = TapAuditor.new(tap, options) + ta = TapAuditor.new(tap, strict: args.strict?) ta.audit if ta.problems.any? @@ -1158,25 +1158,24 @@ module Homebrew class TapAuditor attr_reader :name, :path, :tap_audit_exceptions, :problems - def initialize(tap, options = {}) + def initialize(tap, strict:) @name = tap.name @path = tap.path @tap_audit_exceptions = tap.audit_exceptions - @strict = options[:strict] + @strict = strict @problems = [] end def audit audit_json_files audit_tap_audit_exceptions - self end def audit_json_files - Dir[@path/"**/*.json"].each do |file| - JSON.parse Pathname.new(file).read + Pathname.glob(@path/"**/*.json").each do |file| + JSON.parse file.read rescue JSON::ParserError - problem "#{file.delete_prefix("#{@path}/")} contains invalid JSON" + problem "#{file.to_s.delete_prefix("#{@path}/")} contains invalid JSON" end end @@ -1186,16 +1185,16 @@ module Homebrew invalid_formulae = [] formula_names.each do |name| - invalid_formulae.push name if Formulary.factory(name).tap != @name + invalid_formulae << name if Formula[name].tap != @name rescue FormulaUnavailableError - invalid_formulae.push name + invalid_formulae << name end next if invalid_formulae.empty? problem <<~EOS audit_exceptions/#{list_name}.json references - formulae that were are found in the #{@name} tap. + formulae that are not found in the #{@name} tap. Invalid formulae: #{invalid_formulae.join(", ")} EOS end diff --git a/Library/Homebrew/tap.rb b/Library/Homebrew/tap.rb index ebb0ecd4b2..4b2b081791 100644 --- a/Library/Homebrew/tap.rb +++ b/Library/Homebrew/tap.rb @@ -546,12 +546,12 @@ class Tap def audit_exceptions @audit_exceptions = {} - Dir[path/"audit_exceptions/*"].each do |exception_file| - list_name = File.basename(exception_file).chomp(".json").to_sym + Pathname.glob(path/"audit_exceptions/*").each do |exception_file| + list_name = exception_file.basename.to_s.chomp(".json").to_sym list_contents = begin - JSON.parse Pathname.new(exception_file).read + JSON.parse exception_file.read rescue JSON::ParserError - nil + opoo "#{exception_file} contains invalid JSON" end next if list_contents.nil?