= "..."
should be rewritten as ...
Open
%b= "#{k1}:"
- Read upRead up
- Exclude checks
HamlLint/UnnecessaryStringOutput
Avoid outputting string expressions in Ruby when static text will suffice.
Bad
haml
%tag= "Some #{interpolated} string"
Good: more concise
haml
%tag Some #{interpolated} string
HAML gracefully handles string interpolation in static text, so you don't need to work with Ruby strings in order to use interpolation.
Style/SafeNavigation: Use safe navigation (&.
) instead of checking if an object exists before calling the method. Open
- unless v.nil?
- Read upRead up
- Exclude checks
HamlLint/RuboCop
Option | Description |
---|---|
ignored_cops |
Array of RuboCop cops to ignore. |
This linter integrates with RuboCop
(a static code analyzer and style enforcer) to check the actual Ruby code in
your templates. It will respect any RuboCop-specific configuration you have
set in .rubocop.yml
files, but will explicitly ignore some checks that
don't make sense in the context of HAML documents (like
Style/BlockAlignment
).
-# example.haml
- name = 'James Brown'
- unused_variable = 42
%p Hello #{name}!
Output from haml-lint
example.haml:3 [W] Useless assignment to variable - unused_variable
You can customize which RuboCop warnings you want to ignore by modifying
the ignored_cops
option (see config/default.yml
for the full list of ignored cops).
You can also explicitly set which RuboCop configuration to use via the
HAML_LINT_RUBOCOP_CONF
environment variable. This is intended to be used
by external tools which run the linter on files in temporary directories
separate from the directory where the HAML template originally resided (and
thus where the normal .rubocop.yml
would be picked up).
Displaying Cop Names
You can display the name of the cop by adding the following to your
.rubocop.yml
configuration:
AllCops:
DisplayCopNames: true