This is a scrappy implementation of a cop that checks the following for heredocs:
- Contents may only be indented in increments of 2 spaces.
- Contents may not be indented using spaces.
- Lines may be at max indented 2 spaces more than the line before, ignoring blank lines.
- Copy
heredoc_internal_indentation.rb
to wherever you want in your project - Add the following
.rubocop.yml
, with the correct require location
require: './heredoc_internal_indentation.rb'
Custom/HeredocInternalIndentation:
Enabled: true
- Try running Rubocop normally, and either it works, or you find the bugs I missed.
- There are no tests. I just ran it against
fixture.rb
. - The offense it tied to the node that opens the heredoc instead of offending line.
- This should probably use the indentation config from the
IndentationWidth
cop. - Perhaps the cop should only trigger on certain heredoc delimiters (e.g.
SQL
). - The code could probably use refactoring.
- Probably others things. 🤷♂️