Class: Solargraph::TypeChecker::Rules

Inherits:
Object
  • Object
show all
Defined in:
lib/solargraph/type_checker/rules.rb

Overview

Definitions of type checking rules to be performed at various levels

Constant Summary collapse

LEVELS =
{
  normal: 0,
  typed: 1,
  strict: 2,
  strong: 3,
  alpha: 4
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level, overrides) ⇒ Rules

Returns a new instance of Rules.

Parameters:

  • level (Symbol)
  • overrides (Hash{Symbol => Symbol})


24
25
26
27
28
29
30
31
32
33
# File 'lib/solargraph/type_checker/rules.rb', line 24

def initialize level, overrides
  @rank = if LEVELS.key?(level)
            LEVELS[level]
          else
            Solargraph.logger.warn "Unrecognized TypeChecker level #{level}, assuming normal"
            0
          end
  @level = LEVELS[LEVELS.values.index(@rank)]
  @overrides = overrides
end

Instance Attribute Details

#levelSymbol (readonly)

Returns:

  • (Symbol)


17
18
19
# File 'lib/solargraph/type_checker/rules.rb', line 17

def level
  @level
end

#rankInteger (readonly)

Returns:

  • (Integer)


20
21
22
# File 'lib/solargraph/type_checker/rules.rb', line 20

def rank
  @rank
end

Instance Method Details

#ignore_all_undefined?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/solargraph/type_checker/rules.rb', line 35

def ignore_all_undefined?
  !report_undefined?
end

#must_tag_or_infer?Boolean

Returns:

  • (Boolean)


55
56
57
# File 'lib/solargraph/type_checker/rules.rb', line 55

def must_tag_or_infer?
  report?(:must_tag_or_infer, :strict)
end

#report_undefined?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/solargraph/type_checker/rules.rb', line 39

def report_undefined?
  report?(:report_undefined, :strict)
end

#require_all_unique_types_match_expected?Boolean

TODO:

4: Missed nil violation

TODO:

281: Need to add nil check here

TODO:

22: Translate to something flow sensitive typing understands

TODO:

3: Need a downcast here

TODO:

36: flow sensitive typing needs to handle attrs

TODO:

29: flow sensitive typing should be able to handle redefinition

TODO:

19: flow sensitive typing needs to narrow down type with an if is_a? check

TODO:

13: Need to validate config

TODO:

8: flow sensitive typing should support .class == .class

TODO:

6: need boolish support for ? methods

TODO:

6: flow sensitive typing needs better handling of ||= on lvars

TODO:

5: literal arrays in this module turn into ::Solargraph::Source::Chain::Array

TODO:

5: flow sensitive typing needs to handle ‘raise if’

TODO:

4: flow sensitive typing needs to eliminate literal from union with [:bar].include?(foo)

TODO:

4: nil? support in flow sensitive typing

TODO:

3: flow sensitive typing ought to be able to handle ‘when ClassName’

TODO:

2: downcast output of Enumerable#select

TODO:

2: flow sensitive typing should handle return nil if location&.name.nil?

TODO:

2: flow sensitive typing should handle is_a? and next

TODO:

2: Need to look at Tuple#include? handling

TODO:

2: Should better support meaning of ‘&’ in RBS

TODO:

2: (*) flow sensitive typing needs to handle “if foo = bar”

TODO:

2: flow sensitive typing needs to handle “if foo = bar”

TODO:

2: Need to handle duck-typed method calls on union types

TODO:

2: Need better handling of #compact

TODO:

2: flow sensitive typing should allow shadowing of Kernel#caller

TODO:

1: flow sensitive typing not smart enough to handle this case

TODO:

1: flow sensitive typing needs to handle if foo = bar

TODO:

1: flow sensitive typing needs to handle “if foo.nil?”

TODO:

1: flow sensitive typing should support case/when

TODO:

1: flow sensitive typing should support ivars

TODO:

1: Need to support this in flow sensitive typing

TODO:

1: flow sensitive typing needs to handle self.class == other.class

TODO:

1: flow sensitive typing needs to remove literal with

TODO:

1: flow sensitive typing needs to understand reassignment

TODO:

1: flow sensitive typing should be able to identify more blocks that always return

TODO:

1: should warn on nil dereference below

TODO:

1: flow sensitive typing needs to create separate ranges for postfix if

TODO:

1: flow sensitive typing needs to handle constants

TODO:

1: flow sensitive typing needs to eliminate literal from union with return if foo == :bar

False negatives:

pending code fixes (277):

flow sensitive typing could handle (96):

Returns:

  • (Boolean)


116
117
118
# File 'lib/solargraph/type_checker/rules.rb', line 116

def require_all_unique_types_match_expected?
  report?(:require_all_unique_types_match_expected, :strong)
end

#require_all_unique_types_support_call?Boolean

Returns:

  • (Boolean)


120
121
122
# File 'lib/solargraph/type_checker/rules.rb', line 120

def require_all_unique_types_support_call?
  report?(:require_all_unique_types_support_call, :strong)
end

#require_downcasts?Boolean

Returns:

  • (Boolean)


136
137
138
# File 'lib/solargraph/type_checker/rules.rb', line 136

def require_downcasts?
  report?(:require_downcasts, :alpha)
end

#require_generics_resolved?Boolean

Returns:

  • (Boolean)


128
129
130
# File 'lib/solargraph/type_checker/rules.rb', line 128

def require_generics_resolved?
  report?(:require_generics_resolved, :alpha)
end

#require_inferred_type_params?Boolean

Returns:

  • (Boolean)


63
64
65
# File 'lib/solargraph/type_checker/rules.rb', line 63

def require_inferred_type_params?
  report?(:require_inferred_type_params, :alpha)
end

#require_interfaces_resolved?Boolean

Returns:

  • (Boolean)


132
133
134
# File 'lib/solargraph/type_checker/rules.rb', line 132

def require_interfaces_resolved?
  report?(:require_interfaces_resolved, :alpha)
end

#require_no_undefined_args?Boolean

Returns:

  • (Boolean)


124
125
126
# File 'lib/solargraph/type_checker/rules.rb', line 124

def require_no_undefined_args?
  report?(:require_no_undefined_args, :alpha)
end

#require_type_tags?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/solargraph/type_checker/rules.rb', line 51

def require_type_tags?
  report?(:validate_type_tags, :strong)
end

#validate_calls?Boolean

Returns:

  • (Boolean)


47
48
49
# File 'lib/solargraph/type_checker/rules.rb', line 47

def validate_calls?
  report?(:validate_calls, :strict)
end

#validate_consts?Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/solargraph/type_checker/rules.rb', line 43

def validate_consts?
  report?(:validate_consts, :strict)
end

#validate_sg_ignores?Boolean

We keep this at strong because if you added an @ sg-ignore to address a strong-level issue, then ran at a lower level, you’d get a false positive - we don’t run stronger level checks than requested for performance reasons

Returns:

  • (Boolean)


144
145
146
# File 'lib/solargraph/type_checker/rules.rb', line 144

def validate_sg_ignores?
  report?(:validate_sg_ignores, :strong)
end

#validate_tags?Boolean

Returns:

  • (Boolean)


59
60
61
# File 'lib/solargraph/type_checker/rules.rb', line 59

def validate_tags?
  report?(:validate_tags, :typed)
end