class ERBLint::Linters::GitHub::Accessibility::NoAriaLabelMisuseCounter
Constants
- GENERIC_ELEMENTS
- MESSAGE
- NAME_RESTRICTED_ELEMENTS
- ROLES_WHICH_CANNOT_BE_NAMED
Public Instance Methods
autocorrect(processed_source, offense)
click to toggle source
# File lib/erblint-github/linters/github/accessibility/no_aria_label_misuse_counter.rb, line 40 def autocorrect(processed_source, offense) return unless offense.context lambda do |corrector| if processed_source.file_content.include?("erblint:counter #{simple_class_name}") # update the counter if exists corrector.replace(offense.source_range, offense.context) else # add comment with counter if none corrector.insert_before(processed_source.source_buffer.source_range, "#{offense.context}\n") end end end
run(processed_source)
click to toggle source
# File lib/erblint-github/linters/github/accessibility/no_aria_label_misuse_counter.rb, line 21 def run(processed_source) tags(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 counter_correct?(processed_source) end