Class: Solargraph::Diagnostics::TypeCheck

Inherits:
Base
  • Object
show all
Defined in:
lib/solargraph/diagnostics/type_check.rb

Overview

TypeCheck reports methods with undefined return types, untagged parameters, and invalid param tags.

Instance Attribute Summary

Attributes inherited from Base

#args

Instance Method Summary collapse

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from Solargraph::Diagnostics::Base

Instance Method Details

#diagnose(source, api_map) ⇒ Object


7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/solargraph/diagnostics/type_check.rb', line 7

def diagnose source, api_map
  return [] unless args.include?('always') || api_map.workspaced?(source.filename)
  severity = (args.include?('strict') ? Diagnostics::Severities::ERROR : Diagnostics::Severities::WARNING)
  checker = Solargraph::TypeChecker.new(source.filename, api_map: api_map)
  result = checker.return_type_problems + checker.param_type_problems
  result.concat checker.strict_type_problems if args.include?('strict')
  result.sort! { |a, b| a.location.range.start.line <=> b.location.range.start.line }
  result.map do |problem|
    {
      range: extract_first_line(problem.location, source),
      severity: severity,
      source: 'Typecheck',
      message: problem.message
    }
  end
end