Class: ERBLint::Linters::Primer::Accessibility::DetailsMenuMigration
- Inherits:
-
Linter
- Object
- Linter
- ERBLint::Linters::Primer::Accessibility::DetailsMenuMigration
- Includes:
- Helpers::RuleHelpers, LinterRegistry
- Defined in:
- lib/primer/view_components/linters/details_menu_migration.rb
Overview
Flag when ‘<details-menu>` is being used and offer alternatives.
Defined Under Namespace
Classes: ConfigSchema
Constant Summary collapse
- MIGRATE_FROM_DETAILS_MENU =
"<details-menu> has been deprecated. Please instead use Primer::Alpha::ActionMenu" \ " https://primer.style/design/components/action-menu/rails/alpha"
- DETAILS_MENU_RUBY_PATTERN =
/tag:?\s+:"details-menu"/.freeze
Instance Method Summary collapse
Methods included from Helpers::RuleHelpers
#erb_nodes, #extract_ruby_from_erb_node, #generate_node_offense, #generate_offense, #tags
Instance Method Details
#contains_offense?(code) ⇒ Boolean
42 43 44 45 46 |
# File 'lib/primer/view_components/linters/details_menu_migration.rb', line 42 def contains_offense?(code) return true if code.match?(DETAILS_MENU_RUBY_PATTERN) return code.match?(custom_erb_pattern) if custom_erb_pattern false end |
#custom_erb_pattern ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/primer/view_components/linters/details_menu_migration.rb', line 48 def custom_erb_pattern unless defined?(@custom_erb_pattern) @custom_erb_pattern = if @config.custom_erb_pattern.empty? nil else regexes = @config.custom_erb_pattern.map { |pattern| Regexp.new(pattern, true) } Regexp.new(regexes.join("|"), true) end end @custom_erb_pattern end |
#run(processed_source) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/primer/view_components/linters/details_menu_migration.rb', line 24 def run(processed_source) # HTML tags (processed_source).each do |tag| next if tag.closing? generate_offense(self.class, processed_source, tag, MIGRATE_FROM_DETAILS_MENU) if tag.name == "details-menu" end # ERB nodes erb_nodes(processed_source).each do |node| code = extract_ruby_from_erb_node(node) if contains_offense?(code) generate_node_offense(self.class, processed_source, node, MIGRATE_FROM_DETAILS_MENU) end end end |