Class: A11y::Lint::Rules::MissingAccessibleName

Inherits:
A11y::Lint::Rule show all
Defined in:
lib/a11y/lint/rules/robust/missing_accessible_name.rb

Overview

Checks that link_to, external_link_to, and button_tag calls with empty text or block content include an aria-label (WCAG 4.1.2).

Constant Summary collapse

METHODS =
%w[link_to external_link_to button_tag].freeze

Instance Method Summary collapse

Methods inherited from A11y::Lint::Rule

check, #initialize, rule_name

Constructor Details

This class inherits a constructor from A11y::Lint::Rule

Instance Method Details

#checkObject



13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/a11y/lint/rules/robust/missing_accessible_name.rb', line 13

def check
  return unless (code = @node.ruby_code)

  clean_code = code.sub(/\s+do\s*\z/, "")
  is_block = clean_code != code
  call = parse_call(clean_code)
  return unless call
  return if aria_label_within?(call)
  return unless first_arg_empty_string?(call) || is_block

  offense_message(extract_method_name(call))
end