haml-lint
is a tool to help keep your HAML files
clean and readable. In addition to HAML-specific style and lint checks, it
integrates with RuboCop to bring its
powerful static analysis tools to your HAML documents.
You can run haml-lint
manually from the command line, or integrate it into
your SCM hooks. It uses rules
established by the team at Causes.com.
- Requirements
- Installation
- Usage
- Configuration
- Linters
- Editor Integration
- Git Integration
- Rake Integration
- Contributing
- Changelog
- License
- Ruby 1.9.3+
- HAML 4.0+
gem install haml-lint
Run haml-lint
from the command line by passing in a directory (or multiple
directories) to recursively scan:
haml-lint app/views/
You can also specify a list of files explicitly:
haml-lint app/**/*.html.haml
haml-lint
will output any problems with your HAML, including the offending
filename and line number.
Command Line Flag | Description |
---|---|
-c /--config |
Specify which configuration file to use |
-e /--exclude |
Exclude one or more files from being linted |
-i /--include-linter |
Specify which linters you specifically want to run |
-x /--exclude-linter |
Specify which linters you don't want to run |
--[no-]color |
Whether to output in color |
--show-linters |
Show all registered linters |
-h /--help |
Show command line flag documentation |
-v /--version |
Show version |
haml-lint
will automatically recognize and load any file with the name
.haml-lint.yml
as a configuration file. It loads the configuration based on
the directory haml-lint
is being run from, ascending until a configuration
file is found. Any configuration loaded is automatically merged with the
default configuration (see config/default.yml
).
Here's an example configuration file:
linters:
ImplicitDiv:
enabled: false
LineLength:
max: 100
All linters have an enabled
option which can be true
or false
, which
controls whether the linter is run, along with linter-specific options. The
defaults are defined in config/default.yml
.
Some static blog generators such as Jekyll include
leading frontmatter to the template for their own tracking purposes.
haml-lint
allows you to ignore these headers by specifying the
skip_frontmatter
option in your .haml-lint.yml
configuration:
skip_frontmatter: true
haml-lint
is an opinionated tool that helps you enforce a consistent style in
your HAML files. As an opinionated tool, we've had to make calls about what we
think are the "best" style conventions, even when there are often reasonable
arguments for more than one possible style. While all of our choices have a
rational basis, we think that the opinions themselves are less important than
the fact that haml-lint
provides us with an automated and low-cost means of
enforcing consistency.
If you use vim
, you can have haml-lint
automatically run against your HAML
files after saving by using the
Syntastic plugin. If you already
have the plugin, just add let g:syntastic_haml_checkers = ['haml_lint']
to
your .vimrc
.
If you use SublimeLinter 3
with Sublime Text 3
you can install the
SublimeLinter-haml-lint
plugin using Package Control.
If you use atom
, you can install the linter-haml plugin.
If you'd like to integrate haml-lint
into your Git workflow, check out our
Git hook manager, overcommit.
To execute haml-lint
via a Rake task, add the
following to your Rakefile
:
require 'haml_lint/rake_task'
HamlLint::RakeTask.new
By default, when you execute rake haml_lint
, the above configuration is
equivalent to running haml-lint .
, which will lint all .haml
files in the
current directory and its descendants.
You can customize your task by writing:
require 'haml_lint/rake_task'
HamlLint::RakeTask.new do |t|
t.config = 'custom/config.yml'
t.files = ['app/views', 'custom/*.haml']
t.quiet = true # Don't display output from haml-lint to STDOUT
end
You can also use this custom configuration with a set of files specified via the command line:
# Single quotes prevent shell glob expansion
rake 'haml_lint[app/views, custom/*.haml]'
Files specified in this manner take precedence over the task's files
attribute.
We love getting feedback with or without pull requests. If you do add a new feature, please add tests so that we can avoid breaking it in the future.
Speaking of tests, we use rspec
, which can be run like so:
bundle exec rspec
If you're interested in seeing the changes and bug fixes between each version
of haml-lint
, read the HAML-Lint Changelog.
This project is released under the MIT license.