Class: Guardrails::A11yAudit

Inherits:
Object
  • Object
show all
Defined in:
lib/guardrails/a11y_audit.rb

Overview

Static a11y checks that don’t require a browser — element-level rules that can be answered from the source. For runtime a11y (color contrast, focus order, ARIA tree, dynamic content) integrate axe-core-rspec alongside Guardrails; see doc/A11Y.md.

Defined Under Namespace

Classes: Finding

Constant Summary collapse

SCAN_PATTERNS =
[
  "app/views/**/*.html.erb",
  "app/components/**/*.html.erb"
].freeze
NON_INTERACTIVE_INPUT_TYPES =
%w[hidden submit button reset image].freeze
SUGGESTION_FOR_RULE =
{
  "image_alt" => "add an alt attribute (or alt=\"\" if decorative)",
  "button_name" => "add text, aria-label, or aria-labelledby",
  "link_name" => "add link text, aria-label, or aria-labelledby",
  "input_label" => "add aria-label, aria-labelledby, or a matching <label for=...>"
}.freeze

Instance Method Summary collapse

Constructor Details

#initialize(root:, output: $stdout, style: nil) ⇒ A11yAudit

Returns a new instance of A11yAudit.



34
35
36
37
38
# File 'lib/guardrails/a11y_audit.rb', line 34

def initialize(root:, output: $stdout, style: nil)
  @root = Pathname(root)
  @output = output
  @style = style || Report::Style.new(io: output)
end

Instance Method Details

#runObject



40
41
42
43
44
# File 'lib/guardrails/a11y_audit.rb', line 40

def run
  findings = view_files.flat_map { |path| scan_file(path) }
  print_report(findings)
  findings
end