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) ⇒ Rules

Returns a new instance of Rules.

Parameters:

  • level (Symbol)


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

def initialize level
  @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)]
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)


33
34
35
# File 'lib/solargraph/type_checker/rules.rb', line 33

def ignore_all_undefined?
  rank < LEVELS[:strict]
end

#must_tag_or_infer?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/solargraph/type_checker/rules.rb', line 49

def must_tag_or_infer?
  rank > LEVELS[:typed]
end

#require_all_return_types_match_inferred?Boolean

Returns:

  • (Boolean)


57
58
59
# File 'lib/solargraph/type_checker/rules.rb', line 57

def require_all_return_types_match_inferred?
  rank >= LEVELS[:alpha]
end

#require_type_tags?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/solargraph/type_checker/rules.rb', line 45

def require_type_tags?
  rank >= LEVELS[:strong]
end

#validate_calls?Boolean

Returns:

  • (Boolean)


41
42
43
# File 'lib/solargraph/type_checker/rules.rb', line 41

def validate_calls?
  rank >= LEVELS[:strict]
end

#validate_consts?Boolean

Returns:

  • (Boolean)


37
38
39
# File 'lib/solargraph/type_checker/rules.rb', line 37

def validate_consts?
  rank >= LEVELS[:strict]
end

#validate_tags?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/solargraph/type_checker/rules.rb', line 53

def validate_tags?
  rank > LEVELS[:normal]
end