123456789_123456789_123456789_123456789_123456789_

Class: RBS::CLI::Validate::Errors

Relationships & Source Files
Inherits: Object
Defined in: lib/rbs/cli/validate.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(limit:, exit_error:) ⇒ Errors

[ GitHub ]

  
# File 'lib/rbs/cli/validate.rb', line 7

def initialize(limit:, exit_error:)
  @limit = limit
  @exit_error = exit_error
  @errors = []
  @has_syntax_error = false
end

Instance Method Details

#add(error)

[ GitHub ]

  
# File 'lib/rbs/cli/validate.rb', line 14

def add(error)
  if error.instance_of?(WillSyntaxError)
    RBS.logger.warn(build_message(error))
    @has_syntax_error = true
  else
    @errors << error
  end
  finish if @limit == 1
end

#build_message(error) (private)

[ GitHub ]

  
# File 'lib/rbs/cli/validate.rb', line 41

def build_message(error)
  if error.respond_to?(:detailed_message)
    highlight = RBS.logger_output ? RBS.logger_output.tty? : true
    error.detailed_message(highlight: highlight)
  else
    "#{error.message} (#{error.class})"
  end
end

#finish

[ GitHub ]

  
# File 'lib/rbs/cli/validate.rb', line 24

def finish
  if @errors.empty?
    if @exit_error && @has_syntax_error
      exit 1
    else
      # success
    end
  else
    @errors.each do |error|
      RBS.logger.error(build_message(error))
    end
    exit 1
  end
end