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

Inherits:
Object
  • Object
show all
Defined in:
lib/rbs/cli/validate.rb

Instance Method Summary collapse

Constructor Details

#initialize(limit:, exit_error:) ⇒ Errors

Returns a new instance of Errors.



7
8
9
10
11
12
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
# 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

#finishObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
# 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