A11y::Lint
A Ruby gem for checking accessibility issues in your code.
Installation
Add the gem to your application's Gemfile:
gem "a11y-lint"Then run:
bundle installOr install it directly:
gem install a11y-lintUsage
Command Line
Run the linter on specific files or directories:
a11y-lint app/views/
a11y-lint app/views/home.html.slim app/views/about.html.slimWith no arguments, it scans the current directory recursively for .slim and .erb files:
a11y-lintConfiguration
Create 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/Ruby API
require "a11y/lint"
source = File.read("app/views/home.html.slim")
runner = A11y::Lint::SlimRunner.new([A11y::Lint::Rules::ImgMissingAlt.new])
offenses = runner.run(source, filename: "app/views/home.html.slim")
offenses.each do |offense|
puts "#{offense.filename}:#{offense.line} [#{offense.rule}] #{offense.message}"
endRequirements
- Ruby >= 3.1.0
Development
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.
Contributing
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.
License
The gem is available as open source under the terms of the MIT License.
Code of Conduct
Everyone interacting in the A11y::Lint project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.