Class: Solargraph::TypeChecker::Rules
- Inherits:
-
Object
- Object
- Solargraph::TypeChecker::Rules
- 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
- #level ⇒ Symbol readonly
- #rank ⇒ Integer readonly
Instance Method Summary collapse
- #ignore_all_undefined? ⇒ Boolean
-
#initialize(level, overrides) ⇒ Rules
constructor
A new instance of Rules.
- #must_tag_or_infer? ⇒ Boolean
- #report_undefined? ⇒ Boolean
-
#require_all_unique_types_match_expected? ⇒ Boolean
False negatives:.
- #require_all_unique_types_support_call? ⇒ Boolean
- #require_downcasts? ⇒ Boolean
- #require_generics_resolved? ⇒ Boolean
- #require_inferred_type_params? ⇒ Boolean
- #require_interfaces_resolved? ⇒ Boolean
- #require_no_undefined_args? ⇒ Boolean
- #require_type_tags? ⇒ Boolean
- #validate_calls? ⇒ Boolean
- #validate_consts? ⇒ Boolean
-
#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.
- #validate_tags? ⇒ Boolean
Constructor Details
#initialize(level, overrides) ⇒ Rules
Returns a new instance of Rules.
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
#level ⇒ Symbol (readonly)
17 18 19 |
# File 'lib/solargraph/type_checker/rules.rb', line 17 def level @level end |
#rank ⇒ Integer (readonly)
20 21 22 |
# File 'lib/solargraph/type_checker/rules.rb', line 20 def rank @rank end |
Instance Method Details
#ignore_all_undefined? ⇒ 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
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
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
4: Missed nil violation
281: Need to add nil check here
22: Translate to something flow sensitive typing understands
3: Need a downcast here
36: flow sensitive typing needs to handle attrs
29: flow sensitive typing should be able to handle redefinition
19: flow sensitive typing needs to narrow down type with an if is_a? check
13: Need to validate config
8: flow sensitive typing should support .class == .class
6: need boolish support for ? methods
6: flow sensitive typing needs better handling of ||= on lvars
5: literal arrays in this module turn into ::Solargraph::Source::Chain::Array
5: flow sensitive typing needs to handle ‘raise if’
4: flow sensitive typing needs to eliminate literal from union with [:bar].include?(foo)
4: nil? support in flow sensitive typing
3: flow sensitive typing ought to be able to handle ‘when ClassName’
2: downcast output of Enumerable#select
2: flow sensitive typing should handle return nil if location&.name.nil?
2: flow sensitive typing should handle is_a? and next
2: Need to look at Tuple#include? handling
2: Should better support meaning of ‘&’ in RBS
2: (*) flow sensitive typing needs to handle “if foo = bar”
2: flow sensitive typing needs to handle “if foo = bar”
2: Need to handle duck-typed method calls on union types
2: Need better handling of #compact
2: flow sensitive typing should allow shadowing of Kernel#caller
1: flow sensitive typing not smart enough to handle this case
1: flow sensitive typing needs to handle if foo = bar
1: flow sensitive typing needs to handle “if foo.nil?”
1: flow sensitive typing should support case/when
1: flow sensitive typing should support ivars
1: Need to support this in flow sensitive typing
1: flow sensitive typing needs to handle self.class == other.class
1: flow sensitive typing needs to remove literal with
1: flow sensitive typing needs to understand reassignment
1: flow sensitive typing should be able to identify more blocks that always return
1: should warn on nil dereference below
1: flow sensitive typing needs to create separate ranges for postfix if
1: flow sensitive typing needs to handle constants
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):
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
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
136 137 138 |
# File 'lib/solargraph/type_checker/rules.rb', line 136 def require_downcasts? report?(:require_downcasts, :alpha) end |
#require_generics_resolved? ⇒ 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
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
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
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
51 52 53 |
# File 'lib/solargraph/type_checker/rules.rb', line 51 def report?(:validate_type_tags, :strong) end |
#validate_calls? ⇒ Boolean
47 48 49 |
# File 'lib/solargraph/type_checker/rules.rb', line 47 def validate_calls? report?(:validate_calls, :strict) end |
#validate_consts? ⇒ 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
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
59 60 61 |
# File 'lib/solargraph/type_checker/rules.rb', line 59 def report?(:validate_tags, :typed) end |