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

Included in:
DataStructHelper, MissingTypeAnnotation, RedundantAnnotationWithSkip, RedundantInstanceVariableAnnotation, RedundantTypeAnnotation, UntypedInstanceVariable
Defined in:
lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb,
sig/rubocop/cop/style/rbs_inline/mixin/ast_utils.rbs

Instance Method Summary collapse

Instance Method Details

#args_node_for(node) ⇒ RuboCop::AST::Node

Returns the arguments node of a method definition.

Parameters:

  • node (RuboCop::AST::DefNode)

Returns:

  • (RuboCop::AST::Node)


17
18
19
20
21
22
23
# File 'lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb', line 17

def args_node_for(node) #: RuboCop::AST::Node
  case node.type
  when :def  then node.children[1]
  when :defs then node.children[2]
  else raise
  end
end

#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/mixin/ast_utils.rb', line 10

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

#method_parameter_list_end_line(node) ⇒ Integer

Returns the last line of the method parameter list (the closing ) line, or the def line if no parens).

Parameters:

  • node (RuboCop::AST::DefNode)

Returns:

  • (Integer)


27
28
29
# File 'lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb', line 27

def method_parameter_list_end_line(node) #: Integer
  end_line(args_node_for(node), default: node.location.line)
end

#name_location(node) ⇒ Object

Parameters:

  • node (RuboCop::AST::Node)

Returns:

  • (Object)


32
33
34
35
# File 'lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb', line 32

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

#source!(node) ⇒ String

Parameters:

  • node (RuboCop::AST::Node)

Returns:

  • (String)


38
39
40
# File 'lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb', line 38

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)


45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb', line 45

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