Sha256: 2e0c7cae4f724bbedd62fab6f0e6dbb607a638507d32b9ef5d4698d3e16faa32

Contents?: true

Size: 1.72 KB

Versions: 2

Compression:

Stored size: 1.72 KB

Contents

module Steep
  module Drivers
    class Validate
      attr_reader :signature_dirs
      attr_reader :stdout
      attr_reader :stderr

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

      include Utils::EachSignature

      def run
        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
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
steep-0.11.1 lib/steep/drivers/validate.rb
steep-0.11.0 lib/steep/drivers/validate.rb