audit, tap: incorporate suggestions from code review
This commit is contained in:
		
							parent
							
								
									089810709c
								
							
						
					
					
						commit
						2a941ec6b1
					
				@ -121,7 +121,7 @@ module Homebrew
 | 
				
			|||||||
    # Run tap audits first
 | 
					    # Run tap audits first
 | 
				
			||||||
    if args.tap
 | 
					    if args.tap
 | 
				
			||||||
      tap = Tap.fetch(args.tap)
 | 
					      tap = Tap.fetch(args.tap)
 | 
				
			||||||
      ta = TapAuditor.new(tap, options)
 | 
					      ta = TapAuditor.new(tap, strict: args.strict?)
 | 
				
			||||||
      ta.audit
 | 
					      ta.audit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      if ta.problems.any?
 | 
					      if ta.problems.any?
 | 
				
			||||||
@ -1158,25 +1158,24 @@ module Homebrew
 | 
				
			|||||||
  class TapAuditor
 | 
					  class TapAuditor
 | 
				
			||||||
    attr_reader :name, :path, :tap_audit_exceptions, :problems
 | 
					    attr_reader :name, :path, :tap_audit_exceptions, :problems
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def initialize(tap, options = {})
 | 
					    def initialize(tap, strict:)
 | 
				
			||||||
      @name                 = tap.name
 | 
					      @name                 = tap.name
 | 
				
			||||||
      @path                 = tap.path
 | 
					      @path                 = tap.path
 | 
				
			||||||
      @tap_audit_exceptions = tap.audit_exceptions
 | 
					      @tap_audit_exceptions = tap.audit_exceptions
 | 
				
			||||||
      @strict               = options[:strict]
 | 
					      @strict               = strict
 | 
				
			||||||
      @problems             = []
 | 
					      @problems             = []
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def audit
 | 
					    def audit
 | 
				
			||||||
      audit_json_files
 | 
					      audit_json_files
 | 
				
			||||||
      audit_tap_audit_exceptions
 | 
					      audit_tap_audit_exceptions
 | 
				
			||||||
      self
 | 
					 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def audit_json_files
 | 
					    def audit_json_files
 | 
				
			||||||
      Dir[@path/"**/*.json"].each do |file|
 | 
					      Pathname.glob(@path/"**/*.json").each do |file|
 | 
				
			||||||
        JSON.parse Pathname.new(file).read
 | 
					        JSON.parse file.read
 | 
				
			||||||
      rescue JSON::ParserError
 | 
					      rescue JSON::ParserError
 | 
				
			||||||
        problem "#{file.delete_prefix("#{@path}/")} contains invalid JSON"
 | 
					        problem "#{file.to_s.delete_prefix("#{@path}/")} contains invalid JSON"
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
    end
 | 
					    end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@ -1186,16 +1185,16 @@ module Homebrew
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
        invalid_formulae = []
 | 
					        invalid_formulae = []
 | 
				
			||||||
        formula_names.each do |name|
 | 
					        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
 | 
					        rescue FormulaUnavailableError
 | 
				
			||||||
          invalid_formulae.push name
 | 
					          invalid_formulae << name
 | 
				
			||||||
        end
 | 
					        end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        next if invalid_formulae.empty?
 | 
					        next if invalid_formulae.empty?
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        problem <<~EOS
 | 
					        problem <<~EOS
 | 
				
			||||||
          audit_exceptions/#{list_name}.json references
 | 
					          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(", ")}
 | 
					          Invalid formulae: #{invalid_formulae.join(", ")}
 | 
				
			||||||
        EOS
 | 
					        EOS
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
				
			|||||||
@ -546,12 +546,12 @@ class Tap
 | 
				
			|||||||
  def audit_exceptions
 | 
					  def audit_exceptions
 | 
				
			||||||
    @audit_exceptions = {}
 | 
					    @audit_exceptions = {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    Dir[path/"audit_exceptions/*"].each do |exception_file|
 | 
					    Pathname.glob(path/"audit_exceptions/*").each do |exception_file|
 | 
				
			||||||
      list_name = File.basename(exception_file).chomp(".json").to_sym
 | 
					      list_name = exception_file.basename.to_s.chomp(".json").to_sym
 | 
				
			||||||
      list_contents = begin
 | 
					      list_contents = begin
 | 
				
			||||||
        JSON.parse Pathname.new(exception_file).read
 | 
					        JSON.parse exception_file.read
 | 
				
			||||||
      rescue JSON::ParserError
 | 
					      rescue JSON::ParserError
 | 
				
			||||||
        nil
 | 
					        opoo "#{exception_file} contains invalid JSON"
 | 
				
			||||||
      end
 | 
					      end
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      next if list_contents.nil?
 | 
					      next if list_contents.nil?
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user