Class: ERBLint::Linters::FlashMigrationCounter
- Inherits:
-
BaseLinter
- Object
- Linter
- BaseLinter
- ERBLint::Linters::FlashMigrationCounter
- Includes:
- Autocorrectable
- Defined in:
- lib/primer/view_components/linters/flash_migration_counter.rb
Overview
Counts the number of times a HTML flash is used instead of the component.
Constant Summary collapse
- TAGS =
%w[div].freeze
- CLASSES =
%w[flash].freeze
- MESSAGE =
"We are migrating flashes to use [Primer::Beta::Flash](https://primer.style/view-components/components/beta/flash), please try to use that instead of raw HTML."
- ARGUMENT_MAPPER =
ArgumentMappers::Flash
- COMPONENT =
"Primer::Beta::Flash"
Constants inherited from BaseLinter
BaseLinter::DISALLOWED_CLASSES, BaseLinter::DUMP_FILE, BaseLinter::REQUIRED_ARGUMENTS
Constants included from TagTreeHelpers
TagTreeHelpers::SELF_CLOSING_TAGS
Instance Method Summary collapse
Methods included from Autocorrectable
Methods inherited from BaseLinter
Methods included from Helpers::RuleHelpers
#erb_nodes, #extract_ruby_from_erb_node, #generate_node_offense, #generate_offense, #tags
Methods included from TagTreeHelpers
#build_tag_tree, #self_closing?
Instance Method Details
#map_arguments(tag, tag_tree) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/primer/view_components/linters/flash_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 |