Class: Solargraph::TypeChecker
- Inherits:
-
Object
- Object
- Solargraph::TypeChecker
show all
- Includes:
- ParserGem::NodeMethods, Checks
- Defined in:
- lib/solargraph/type_checker.rb,
lib/solargraph/type_checker/rules.rb,
lib/solargraph/type_checker/checks.rb,
lib/solargraph/type_checker/problem.rb,
lib/solargraph/type_checker/param_def.rb
Overview
A static analysis tool for validating data types.
Defined Under Namespace
Modules: Checks
Classes: ParamDef, Problem, Rules
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Checks
all_types_match?, any_types_match?, duck_types_match?, either_way?, fuzz, types_match?
Constructor Details
#initialize(filename, api_map: nil, level: :normal, workspace: filename ? Workspace.new(File.dirname(filename)) : nil, rules: workspace ? workspace.rules(level) : Rules.new(level, {})) ⇒ TypeChecker
Returns a new instance of TypeChecker.
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/solargraph/type_checker.rb', line 32
def initialize filename,
api_map: nil,
level: :normal,
workspace: filename ? Workspace.new(File.dirname(filename)) : nil,
rules: workspace ? workspace.rules(level) : Rules.new(level, {})
@filename = filename
@api_map = api_map || Solargraph::ApiMap.load(File.dirname(filename))
@rules = rules
@marked_ranges = []
end
|
Instance Attribute Details
22
23
24
|
# File 'lib/solargraph/type_checker.rb', line 22
def api_map
@api_map
end
|
#filename ⇒ String
16
17
18
|
# File 'lib/solargraph/type_checker.rb', line 16
def filename
@filename
end
|
19
20
21
|
# File 'lib/solargraph/type_checker.rb', line 19
def rules
@rules
end
|
Class Method Details
.load(filename, level = :normal) ⇒ self
71
72
73
74
75
76
|
# File 'lib/solargraph/type_checker.rb', line 71
def load filename, level = :normal
source = Solargraph::Source.load(filename)
api_map = Solargraph::ApiMap.new
api_map.map(source)
new(filename, api_map: api_map, level: level)
end
|
.load_string(code, filename = nil, level = :normal) ⇒ self
82
83
84
85
86
87
|
# File 'lib/solargraph/type_checker.rb', line 82
def load_string code, filename = nil, level = :normal
source = Solargraph::Source.load_string(code, filename)
api_map = Solargraph::ApiMap.new
api_map.map(source)
new(filename, api_map: api_map, level: level)
end
|
Instance Method Details
#problems ⇒ Array<Problem>
56
57
58
59
60
61
62
63
64
65
|
# File 'lib/solargraph/type_checker.rb', line 56
def problems
@problems ||= begin
all = method_tag_problems
.concat(variable_type_tag_problems)
.concat(const_problems)
.concat(call_problems)
unignored = without_ignored(all)
unignored.concat(unneeded_sgignore_problems)
end
end
|
51
52
53
|
# File 'lib/solargraph/type_checker.rb', line 51
def source
@source_map.source
end
|
46
47
48
|
# File 'lib/solargraph/type_checker.rb', line 46
def source_map
@source_map ||= api_map.source_map(filename)
end
|