Class: Steep::Drivers::Check
- Inherits:
-
Object
- Object
- Steep::Drivers::Check
- Includes:
- Utils::DriverHelper
- Defined in:
- lib/steep/drivers/check.rb
Instance Attribute Summary collapse
-
#command_line_patterns ⇒ Object
readonly
Returns the value of attribute command_line_patterns.
-
#dump_all_types ⇒ Object
Returns the value of attribute dump_all_types.
-
#stderr ⇒ Object
readonly
Returns the value of attribute stderr.
-
#stdout ⇒ Object
readonly
Returns the value of attribute stdout.
Attributes included from Utils::DriverHelper
Instance Method Summary collapse
-
#initialize(stdout:, stderr:) ⇒ Check
constructor
A new instance of Check.
- #output_types(typing) ⇒ Object
- #run ⇒ Object
Methods included from Utils::DriverHelper
Constructor Details
#initialize(stdout:, stderr:) ⇒ Check
Returns a new instance of Check.
12 13 14 15 16 17 18 |
# File 'lib/steep/drivers/check.rb', line 12 def initialize(stdout:, stderr:) @stdout = stdout @stderr = stderr @command_line_patterns = [] self.dump_all_types = false end |
Instance Attribute Details
#command_line_patterns ⇒ Object (readonly)
Returns the value of attribute command_line_patterns.
6 7 8 |
# File 'lib/steep/drivers/check.rb', line 6 def command_line_patterns @command_line_patterns end |
#dump_all_types ⇒ Object
Returns the value of attribute dump_all_types.
8 9 10 |
# File 'lib/steep/drivers/check.rb', line 8 def dump_all_types @dump_all_types end |
#stderr ⇒ Object (readonly)
Returns the value of attribute stderr.
5 6 7 |
# File 'lib/steep/drivers/check.rb', line 5 def stderr @stderr end |
#stdout ⇒ Object (readonly)
Returns the value of attribute stdout.
4 5 6 |
# File 'lib/steep/drivers/check.rb', line 4 def stdout @stdout end |
Instance Method Details
#output_types(typing) ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/steep/drivers/check.rb', line 86 def output_types(typing) lines = [] typing.each_typing do |node, _| begin type = typing.type_of(node: node) lines << [node.loc.expression.source_buffer.name, [node.loc.last_line,node.loc.last_column], [node.loc.first_line, node.loc.column], node, type] rescue lines << [node.loc.expression.source_buffer.name, [node.loc.last_line,node.loc.last_column], [node.loc.first_line, node.loc.column], node, nil] end end lines.sort {|x,y| y <=> x }.reverse_each do |line| source = line[3].loc.expression.source stdout.puts "#{line[0]}:(#{line[2].join(",")}):(#{line[1].join(",")}):\t#{line[3].type}:\t#{line[4]}\t(#{source.split(/\n/).first})" end end |
#run ⇒ Object
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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/steep/drivers/check.rb', line 20 def run project = load_config() loader = Project::FileLoader.new(project: project) loader.load_sources(command_line_patterns) loader.load_signatures() type_check(project) if self.dump_all_types project.targets.each do |target| case (status = target.status) when Project::Target::TypeCheckStatus target.source_files.each_value do |file| case (file_status = file.status) when Project::SourceFile::TypeCheckStatus output_types(file_status.typing) end end end end end 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) when Project::Target::TypeCheckStatus status.type_check_sources.each do |source_file| case source_file.status when Project::SourceFile::TypeCheckStatus source_file.errors.reject do |error| case when error.is_a?(Errors::FallbackAny) target..allow_fallback_any when error.is_a?(Errors::MethodDefinitionMissing) target..allow_missing_definitions when error.is_a?(Errors::NoMethod) target..allow_unknown_method_calls when error.is_a?(Errors::UnknownConstantAssigned) target..allow_unknown_constant_assignment end end.each do |error| error.print_to stdout end when Project::SourceFile::TypeCheckErrorStatus Steep.log_error source_file.status.error end end end end end if project.targets.all? {|target| target.status.is_a?(Project::Target::TypeCheckStatus) && target.no_error? && target.errors.empty? } Steep.logger.info "No type error found" return 0 end 1 end |