Class: A11y::Lint::PhlexRunner

Inherits:
Object
  • Object
show all
Defined in:
lib/a11y/lint/phlex_runner.rb

Overview

Parses Phlex view classes and checks them against accessibility rules.

Constant Summary collapse

PHLEX_PATTERN =
/\bdef\s+view_template\b/
TEXT_CALLS =

Phlex auto-emits the return value of these calls into the document: ‘plain` / `text` are built-in; the rest are registered as value helpers by phlex-rails via `register_value_helper`.

%w[
  plain text
  t translate l localize
  pluralize truncate
  number_to_currency number_to_human number_to_human_size
  number_to_percentage number_to_phone
  number_with_delimiter number_with_precision
  highlight excerpt
].to_set.freeze

Instance Method Summary collapse

Constructor Details

#initialize(rules = nil, configuration: Configuration.new) ⇒ PhlexRunner

Returns a new instance of PhlexRunner.



25
26
27
28
# File 'lib/a11y/lint/phlex_runner.rb', line 25

def initialize(rules = nil, configuration: Configuration.new)
  @rules = rules || configuration.enabled_rules
  @configuration = configuration
end

Instance Method Details

#run(source, filename:) ⇒ Object



30
31
32
33
34
35
36
37
38
39
# File 'lib/a11y/lint/phlex_runner.rb', line 30

def run(source, filename:)
  return [] unless source.match?(PHLEX_PATTERN)

  @source = source
  @filename = filename
  @offenses = []

  walk(Prism.parse(source).value)
  @offenses
end