I'm seeing an issue where Layout/LeadingEmptyLines autocorrect deletes the <% delimiter and breaks the template, using: erb_lint 0.9.0, rubocop 1.84.2, ruby 4.0.2
Save this five-line file as bug.html.erb:
<%
bar = 1
baz = 2
%>
<p><%= bar + baz %></p>
(e.g. printf '<%%\n bar = 1\n baz = 2\n%%>\n<p><%%= bar + baz %%></p>\n' > bug.html.erb)
Run bundle exec erb_lint bug.html.erb (with standard-erb-lint / the default Rubocop-backed ruleset, in particular Layout/LeadingEmptyLines enabled as autocorrectable).
It reports:
Layout/LeadingEmptyLines: Unnecessary blank line at the beginning of the source.
In file: bug.html.erb:2
Layout/TrailingWhitespace: Trailing whitespace detected.
In file: bug.html.erb:1
2 error(s) were found in ERB files
After autofixing (bundle exec erb_lint -a bug.html.erb) the now-4-line file reads:
bar = 1
baz = 2
%>
<p><%= bar + baz %></p>
The opening <% delimiter has been removed. bar = 1 and baz = 2 are now literal HTML text, the closing %> is orphaned, and the template raises undefined local variable or method 'bar' at render time.
Expected: the autofix should leave multi-line <% ... %>blocks alone when the "leading empty line" it detects is the newline immediately after the opening <% delimiter.
Workaround: keep Ruby inside <% %> on a single line per statement so RuboCop's Layout cops have nothing to rewrite across the ERB boundary.
I'm seeing an issue where
Layout/LeadingEmptyLinesautocorrect deletes the<%delimiter and breaks the template, using: erb_lint 0.9.0, rubocop 1.84.2, ruby 4.0.2Save this five-line file as
bug.html.erb:(e.g.
printf '<%%\n bar = 1\n baz = 2\n%%>\n<p><%%= bar + baz %%></p>\n' > bug.html.erb)Run
bundle exec erb_lint bug.html.erb(withstandard-erb-lint/ the default Rubocop-backed ruleset, in particularLayout/LeadingEmptyLinesenabled as autocorrectable).It reports:
After autofixing (
bundle exec erb_lint -a bug.html.erb) the now-4-line file reads:The opening
<%delimiter has been removed.bar = 1andbaz = 2are now literal HTML text, the closing%>is orphaned, and the template raisesundefined local variable or method 'bar'at render time.Expected: the autofix should leave multi-line
<% ... %>blocks alone when the "leading empty line" it detects is the newline immediately after the opening<%delimiter.Workaround: keep Ruby inside
<% %>on a single line per statement so RuboCop's Layout cops have nothing to rewrite across the ERB boundary.