Class: ERBLint::Linters::GitHub::Accessibility::NoAriaLabelMisuse
- Inherits:
-
Linter
- Object
- Linter
- ERBLint::Linters::GitHub::Accessibility::NoAriaLabelMisuse
- Includes:
- CustomHelpers, LinterRegistry
- Defined in:
- lib/erblint-github/linters/github/accessibility/no_aria_label_misuse.rb
Constant Summary collapse
- GENERIC_ELEMENTS =
%w[span div].freeze
- NAME_RESTRICTED_ELEMENTS =
%w[h1 h2 h3 h4 h5 h6 strong i p b code].freeze
- ROLES_WHICH_CANNOT_BE_NAMED =
%w[caption code definition deletion emphasis insertion mark none paragraph presentation strong subscript suggestion superscript term time].freeze
- MESSAGE =
"[aria-label] and [aria-labelledby] usage are only reliably supported on interactive elements and a subset of ARIA roles"
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
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/erblint-github/linters/github/accessibility/no_aria_label_misuse.rb', line 21 def run(processed_source) (processed_source).each do |tag| next if tag.closing? next unless possible_attribute_values(tag, "aria-label").present? || possible_attribute_values(tag, "aria-labelledby").present? if NAME_RESTRICTED_ELEMENTS.include?(tag.name) generate_offense(self.class, processed_source, tag) elsif GENERIC_ELEMENTS.include?(tag.name) role = possible_attribute_values(tag, "role") if role.present? generate_offense(self.class, processed_source, tag) if ROLES_WHICH_CANNOT_BE_NAMED.include?(role.join) else generate_offense(self.class, processed_source, tag) end end end end |