Class: ERBLint::Linters::GitHub::Accessibility::NoRedundantImageAlt
- Inherits:
-
Linter
- Object
- Linter
- ERBLint::Linters::GitHub::Accessibility::NoRedundantImageAlt
- Includes:
- CustomHelpers, LinterRegistry
- Defined in:
- lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb
Constant Summary collapse
- MESSAGE =
"<img> alt prop should not contain `image` or `picture` as screen readers already announce the element as an image"
- REDUNDANT_ALT_WORDS =
%w[image picture].freeze
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
16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/erblint-github/linters/github/accessibility/no_redundant_image_alt.rb', line 16 def run(processed_source) (processed_source).each do |tag| next if tag.name != "img" next if tag.closing? alt = possible_attribute_values(tag, "alt").join next if alt.empty? generate_offense(self.class, processed_source, tag) if (alt.downcase.split & REDUNDANT_ALT_WORDS).any? end end |