A Ruby gem for checking accessibility issues in your code.
Add the gem to your application's Gemfile:
gem "a11y-lint"Then run:
bundle installOr install it directly:
gem install a11y-lintRun the linter on specific files or directories:
a11y-lint app/views/
a11y-lint app/views/home.html.erb app/views/about.html.erbWith no arguments, it scans the current directory recursively for .erb and .rb (Phlex) files:
a11y-lintCreate a .a11y-lint.yml file in your project root to enable or disable individual rules:
ImgMissingAlt:
Enabled: false
ImageTagMissingAlt:
Enabled: trueRules not listed in the file are enabled by default. The linter searches for .a11y-lint.yml starting from the target directory and walking up to the filesystem root.
To specify a config file explicitly:
a11y-lint --config path/to/.a11y-lint.yml app/views/require "a11y/lint"
# ERB
source = File.read("app/views/home.html.erb")
runner = A11y::Lint::ErbRunner.new([A11y::Lint::Rules::ImgMissingAlt])
offenses = runner.run(source, filename: "app/views/home.html.erb")
# Phlex
source = File.read("app/views/home_view.rb")
runner = A11y::Lint::PhlexRunner.new([A11y::Lint::Rules::ImgMissingAlt])
offenses = runner.run(source, filename: "app/views/home_view.rb")
offenses.each do |offense|
puts "#{offense.filename}:#{offense.line} [#{offense.rule}] #{offense.message}"
end- Ruby >= 3.1.0
After checking out the repo, run bin/setup to install dependencies. Then, run bundle exec rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To run all checks (tests + linting):
bundle exec rakeTo install this gem onto your local machine, run bundle exec rake install.
Bug reports and pull requests are welcome on GitHub at https://github.com/Guided-Rails/a11y-lint. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.
The gem is available as open source under the terms of the MIT License.
Everyone interacting in the A11y::Lint project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.