Class: Steep::Drivers::Validate

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Utils::EachSignature

#each_file_in_dir, #each_file_in_path

Constructor Details

#initialize(signature_dirs:, stdout:, stderr:) ⇒ Validate



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

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

  self.verbose = false
end

Instance Attribute Details

#signature_dirsObject (readonly)

Returns the value of attribute signature_dirs.



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

def signature_dirs
  @signature_dirs
end

#stderrObject (readonly)

Returns the value of attribute stderr.



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

def stderr
  @stderr
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



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

def stdout
  @stdout
end

#verboseObject

Returns the value of attribute verbose.



7
8
9
# File 'lib/steep/drivers/validate.rb', line 7

def verbose
  @verbose
end

Instance Method Details

#runObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/steep/drivers/validate.rb', line 19

def run
  Steep.logger.level = Logger::DEBUG if verbose

  project = Project.new

  signature_dirs.each do |path|
    each_file_in_path(".rbi", path) do |file_path|
      file = Project::SignatureFile.new(path: file_path)
      file.content = file_path.read
      project.signature_files[file_path] = file
    end
  end

  project.type_check

  case project.signature
  when Project::SignatureHasError
    project.signature.errors.each do |error|
      case error
      when Interface::Instantiated::InvalidMethodOverrideError
        stdout.puts "😱 #{error.message}"
        error.result.trace.each do |s, t|
          case s
          when Interface::Method
            stdout.puts "  #{s.name}(#{s.type_name}) <: #{t.name}(#{t.type_name})"
          when Interface::MethodType
            stdout.puts "  #{s} <: #{t} (#{s.location&.name||"?"}:#{s.location&.start_line||"?"})"
          else
            stdout.puts "  #{s} <: #{t}"
          end
        end
        stdout.puts "  🚨 #{error.result.error.message}"
      when Interface::Instantiated::InvalidIvarOverrideError
        stdout.puts "😱 #{error.message}"
      else
        stdout.puts "😱 #{error.inspect}"
      end
    end
    1
  else
    0
  end
end