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

Included in:
DataClassCommentAlignment, MissingDataClassAnnotation, MissingTypeAnnotation, RedundantInstanceVariableAnnotation, UntypedInstanceVariable
Defined in:
lib/rubocop/cop/style/rbs_inline/ast_utils.rb,
sig/rubocop/cop/style/rbs_inline/ast_utils.rbs

Instance Method Summary collapse

Instance Method Details

#end_line(node, default:) ⇒ Integer

Parameters:

  • node (RuboCop::AST::Node)
  • default: (Integer)

Returns:

  • (Integer)


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

Parameters:

  • node (RuboCop::AST::Node)

Returns:

  • (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) ⇒ String

Parameters:

  • node (RuboCop::AST::Node)

Returns:

  • (String)


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(arg0) ⇒ Symbol #value_to_sym(arg0) ⇒ Symbol #value_to_sym(arg0) ⇒ Symbol?

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

Overloads:

  • #value_to_sym(arg0) ⇒ Symbol

    Parameters:

    • arg0 (RuboCop::AST::SymbolNode)

    Returns:

    • (Symbol)
  • #value_to_sym(arg0) ⇒ Symbol

    Parameters:

    • arg0 (RuboCop::AST::StrNode)

    Returns:

    • (Symbol)
  • #value_to_sym(arg0) ⇒ Symbol?

    Parameters:

    • arg0 (RuboCop::AST::Node)

    Returns:

    • (Symbol, nil)


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