44 lines
998 B
Ruby
Raw Normal View History

2020-10-10 14:16:11 +02:00
# typed: true
# frozen_string_literal: true
module RuboCop
module Cask
module AST
# This class wraps the AST method node that represents the cask header. It
# includes various helper methods to aid cops in their analysis.
class CaskHeader
def initialize(method_node)
@method_node = method_node
end
attr_reader :method_node
def header_str
@header_str ||= source_range.source
end
def source_range
@source_range ||= method_node.loc.expression
end
2020-10-20 12:03:48 +02:00
sig { returns(String) }
def preferred_header_str
"cask '#{cask_token}'"
end
def cask_token
2023-05-10 00:55:54 +02:00
@cask_token ||= method_node.first_argument.str_content
end
def hash_node
@hash_node ||= method_node.each_child_node(:hash).first
end
def pair_node
@pair_node ||= hash_node.each_child_node(:pair).first
end
end
end
end
end