Class: ERBLint::Linters::GitHub::Accessibility::AriaLabelIsWellFormatted

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

Defined Under Namespace

Classes: ConfigSchema

Constant Summary collapse

MESSAGE =
"[aria-label] text should be formatted the same as you would visual text. Use sentence case, and don't format it like an ID. Additionally, `aria-label` should be concise and should not contain line breaks."

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
# File 'lib/erblint-github/linters/github/accessibility/aria_label_is_well_formatted.rb', line 21

def run(processed_source)
  tags(processed_source).each do |tag|
    next if tag.closing?

    aria_label = possible_attribute_values(tag, "aria-label").join

    if (aria_label.start_with?(/^[a-z]/) || aria_label.match?(/[\r\n]+/)) && !@config.exceptions.include?(aria_label)
      generate_offense(self.class, processed_source, tag)
    end
  end
end