Class: ERBLint::Linters::GitHub::Accessibility::NavigationHasLabel

Inherits:
Linter
  • Object
show all
Includes:
CustomHelpers, LinterRegistry
Defined in:
lib/erblint-github/linters/github/accessibility/navigation_has_label.rb

Constant Summary collapse

MESSAGE =
"The navigation landmark should have a unique accessible name via `aria-label` or `aria-labelledby`. Remember that the name does not need to include `navigation` or `nav` since it will already be announced."

Constants included from CustomHelpers

CustomHelpers::INTERACTIVE_ELEMENTS

Instance Method Summary collapse

Methods included from CustomHelpers

#basic_conditional_code_check, #counter_correct?, #focusable?, #generate_offense, #generate_offense_from_source_range, #possible_attribute_values, #simple_class_name, #tags

Instance Method Details

#run(processed_source) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/erblint-github/linters/github/accessibility/navigation_has_label.rb', line 15

def run(processed_source)
  tags(processed_source).each do |tag|
    next if tag.closing?
    next unless possible_attribute_values(tag, "role").include?("navigation") || tag.name == "nav"
    if possible_attribute_values(tag, "aria-label").empty? && possible_attribute_values(tag, "aria-labelledby").empty?
      message = MESSAGE
      if tag.name != "nav"
        message += "Additionally, you can safely drop the `role='navigation'` and replace it with the native HTML `nav` element."
      end
      generate_offense(self.class, processed_source, tag, message)
    end

  end
end