Module: RuboCop::Cop::Style::RbsInline::ASTUtils

Instance Method Summary collapse

Instance Method Details

#end_line(node, default:) ⇒ Object



10
11
12
13
# File 'lib/rubocop/cop/style/rbs_inline/ast_utils.rb', line 10

def end_line(node, default:) #: Integer
  location = node.location #: untyped
  location.end&.line || default
end

#name_location(node) ⇒ Object



16
17
18
19
# File 'lib/rubocop/cop/style/rbs_inline/ast_utils.rb', line 16

def name_location(node) #: untyped
  location = node.location #: untyped
  location.name
end

#source!(node) ⇒ Object



22
23
24
# File 'lib/rubocop/cop/style/rbs_inline/ast_utils.rb', line 22

def source!(node) #: String
  node.source || raise
end

#value_to_sym(node) ⇒ Object

: (RuboCop::AST::SymbolNode) -> Symbol : (RuboCop::AST::StrNode) -> Symbol : (RuboCop::AST::Node) -> Symbol?



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/rubocop/cop/style/rbs_inline/ast_utils.rb', line 29

def value_to_sym(node)
  case node
  when RuboCop::AST::SymbolNode
    node.value
  when RuboCop::AST::StrNode
    case (v = node.value)
    when String
      v.to_sym
    else
      value_to_sym(v)
    end
  end
end