class ERBLint::Linters::FlashComponentMigrationCounter

Counts the number of times a HTML flash is used instead of the component.

Constants

ARGUMENT_MAPPER
CLASSES
COMPONENT
MESSAGE
TAGS

Public Instance Methods

map_arguments(tag, tag_tree) click to toggle source
# File lib/primer/view_components/linters/flash_component_migration_counter.rb, line 19
def map_arguments(tag, tag_tree)
  # We can only autocorrect elements with simple text as content.
  return nil if tag_tree[:children].size != 1
  # Hash children indicates that there are tags in the content.
  return nil if tag_tree[:children].first.is_a?(Hash)

  content = tag_tree[:children].first

  # Don't accept content with ERB blocks
  return nil if content.type != :text || content.children&.any? { |n| n.try(:type) == :erb }

  ARGUMENT_MAPPER.new(tag).to_s
rescue ArgumentMappers::ConversionError
  nil
end