in lib/primer/view_components/linters/close_button_component_migration_counter.rb [24:73]
def map_arguments(tag, tag_tree)
return if tag_tree[:children].size != 1
nodes = tag_tree[:children].first.children
erb_nodes = nodes.select { |node| node.try(:type) == :erb }
return if erb_nodes.size != 1
_, _, code_node = *erb_nodes.first
code = code_node.children.first.strip
ast = erb_ast(code)
if ast.method_name == :primer_octicon || ast.method_name == :octicon
octicon_kwargs = ast.arguments[1]
icon = icon(ast.arguments)
elsif ast.method_name == :render && code.include?("Primer::OcticonComponent")
octicon_kwargs = ast.arguments.first.arguments.last
icon = icon(ast.arguments.first.arguments)
else
return
end
return unless icon == :x
return if custom_attributes?(octicon_kwargs)
octicon_aria_label = aria_label_from_octicon(octicon_kwargs)
tag_aria_label = tag.attributes.each.find { |a| a.name == "aria-label" }
return if octicon_aria_label.blank? && tag_aria_label.blank?
args = ARGUMENT_MAPPER.new(tag).to_s
return args if tag_aria_label.present?
aria_label_arg = "\"aria-label\": #{octicon_aria_label}"
return aria_label_arg if args.blank?
"#{args}, #{aria_label_arg}"
rescue ArgumentMappers::ConversionError
nil
end