Module: RuboCop::Cop::Style::RbsInline::ASTUtils
- Included in:
- DataDefineWithBlock, DataStructHelper, MissingTypeAnnotation, RedundantAnnotationWithSkip, RedundantInstanceVariableAnnotation, RedundantTypeAnnotation, StructNewWithBlock, 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
-
#args_node_for(node) ⇒ RuboCop::AST::Node
Returns the arguments node of a method definition.
-
#assigned_constant_name(node) ⇒ String?
Returns the name of the constant
nodeis assigned to, ornilwhen the name is not statically determinable (e.g.self::Foo = ...). - #end_line(node, default:) ⇒ Integer
-
#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).
- #name_location(node) ⇒ Object
- #source!(node) ⇒ String
-
#value_to_sym(node) ⇒ Object
: (RuboCop::AST::SymbolNode) -> Symbol : (RuboCop::AST::StrNode) -> Symbol : (RuboCop::AST::Node) -> Symbol?.
Instance Method Details
#args_node_for(node) ⇒ RuboCop::AST::Node
Returns the arguments node of a method definition.
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 |
#assigned_constant_name(node) ⇒ String?
Returns the name of the constant node is assigned to, or nil when the name
is not statically determinable (e.g. self::Foo = ...).
45 46 47 48 49 50 51 52 53 |
# File 'lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb', line 45 def assigned_constant_name(node) #: String? parent = node.parent return nil unless parent.is_a?(RuboCop::AST::CasgnNode) return nil unless parent.each_path.all? { _1.const_type? || _1.cbase_type? } # `const_name` drops the leading `::`, which would name a different constant # when the assignment appears inside a namespace. parent.absolute? ? "::#{parent.const_name}" : parent.const_name end |
#end_line(node, default:) ⇒ 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).
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
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
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?
58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubocop/cop/style/rbs_inline/mixin/ast_utils.rb', line 58 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 |