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
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(level) ⇒ Rules

Returns a new instance of Rules.

Parameters:

  • level (Symbol)


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

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)


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

def level
  @level
end

#rankInteger (readonly)

Returns:

  • (Integer)


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

def rank
  @rank
end

Instance Method Details

#ignore_all_undefined?Boolean

Returns:

  • (Boolean)


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

def ignore_all_undefined?
  rank < LEVELS[:strict]
end

#must_tag_or_infer?Boolean

Returns:

  • (Boolean)


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

def must_tag_or_infer?
  rank > LEVELS[:typed]
end

#require_type_tags?Boolean

Returns:

  • (Boolean)


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

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

#validate_calls?Boolean

Returns:

  • (Boolean)


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

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

#validate_consts?Boolean

Returns:

  • (Boolean)


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

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

#validate_tags?Boolean

Returns:

  • (Boolean)


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

def validate_tags?
  rank > LEVELS[:normal]
end