Class: Steep::Drivers::Validate

Inherits:
Object
  • Object
show all
Includes:
Utils::DriverHelper
Defined in:
lib/steep/drivers/validate.rb

Instance Attribute Summary collapse

Attributes included from Utils::DriverHelper

#steepfile

Instance Method Summary collapse

Methods included from Utils::DriverHelper

#load_config, #type_check

Constructor Details

#initialize(stdout:, stderr:) ⇒ Validate

Returns a new instance of Validate.



9
10
11
12
# File 'lib/steep/drivers/validate.rb', line 9

def initialize(stdout:, stderr:)
  @stdout = stdout
  @stderr = stderr
end

Instance Attribute Details

#stderrObject (readonly)

Returns the value of attribute stderr.



5
6
7
# File 'lib/steep/drivers/validate.rb', line 5

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/steep/drivers/validate.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#runObject



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/steep/drivers/validate.rb', line 14

def run
  project = load_config()

  loader = Project::FileLoader.new(project: project)
  loader.load_signatures()

  type_check(project)

  project.targets.each do |target|
    Steep.logger.tagged "target=#{target.name}" do
      case (status = target.status)
      when Project::Target::SignatureSyntaxErrorStatus
        printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
        printer.print_syntax_errors(status.errors)
      when Project::Target::SignatureValidationErrorStatus
        printer = SignatureErrorPrinter.new(stdout: stdout, stderr: stderr)
        printer.print_semantic_errors(status.errors)
      end
    end
  end

  project.targets.all? {|target| target.status.is_a?(Project::Target::TypeCheckStatus) } ? 0 : 1
end