Use .rubocop_todo/**/*.yml for HAML exclusions
Problem
haml-lint
supports RuboCop
When introducing new RuboCop rules which affect HAML files we either:
- Fix all the offenses in HAML files OR
- Ignore cop rule via
ignored_cops
, for example:
linters:
# ...
RuboCop:
enabled: true
ignored_cops:
# These cops are incredibly noisy when it comes to HAML templates, so we
# ignore them.
- ...
# These ^^^ ignores are permanent.
# These cops should eventually get enabled
- Cop/LineBreakAfterGuardClauses
- Cop/ProjectPathHelper
- Gitlab/Json
- GitlabSecurity/PublicSend
# ...and many more
Disabling cop rules, however, does not prevent from accumulating new offenses in HAML files.
We only seldom fix all the offenses in HAML files re-enable these cops again.
Proposed solution
In order to prevent new offenses from sneaking into the code base we could:
- Enable RuboCop rules in
.haml-lint.yml
listed under# These cops should eventually get enabled
- Exclude HAML files with offenses in
.rubocop_todo/**/*.yml
- Let
RuboCop::Formatter::TodoFormatter
(used byrake rubocop:todo:generate
) ignore HAML files
Implementation guide
-
Ignore HAML files excludes in RuboCop TODO directory - !123642 (merged) -
Add a rake task lint:haml:todo:generate
to exclude HAML files with offenses in.rubocop_todo/**/*.yml
-
Enable ignored RuboCop rules in .haml-lint.yml
and exclude HAML files - !115858 (closed)
Caveats
Because the way haml-lint
extracts Ruby code from HAML the HAML files need to and with .rb
.
For example, the HAML file ee/app/views/groups/epics/index.html.haml
becomes ee/app/views/groups/epics/index.html.haml.rb
in .rubocop_todo/gitlab/feature_available_usage.yml
. Same for other formats like text
or atom
(*.text.haml
or *.atom.haml
) etc.
Alternatives
Alternatively, we could use a RuboCop plugin rubocop-haml
and stop using RuboCop in haml-lint
. This plugin has some rough edges and the approach above seems like a good in-between step.
See MR.