Skip to content

Post-merge-review: Fix template-no-multiple-empty-lines: detect trailing empty lines and fix reported location#2661

Merged
NullVoxPopuli merged 1 commit intoember-cli:masterfrom
johanrd:night_fix/template-no-multiple-empty-lines
Apr 13, 2026
Merged

Post-merge-review: Fix template-no-multiple-empty-lines: detect trailing empty lines and fix reported location#2661
NullVoxPopuli merged 1 commit intoember-cli:masterfrom
johanrd:night_fix/template-no-multiple-empty-lines

Conversation

@johanrd
Copy link
Copy Markdown
Contributor

@johanrd johanrd commented Apr 13, 2026

What's broken on master

Two bugs in the line-scanning loop:

  1. Trailing empty lines silently ignored. The rule reports only when a non-empty line is encountered after a streak of empty lines, so a file ending with …foo\n\n\n (three newlines) never reports. Upstream handles this by iterating allLines.length + 1 (no-multiple-empty-lines.js L49).
  2. Inverted error location. Master computes start.line = firstEmptyLine + max + 2 and end.line = index, producing start.line > end.line in real cases.

Fix

  • Swallow the final newline — strip the last element when it's empty, matching upstream L15 (source.at(-1) === '' ? source.slice(0, -1) : source).
  • Add post-loop reportExcess call for trailing empty lines.
  • Correct the loc computation.
  • Extract the reporting into a shared reportExcess function so both the mid-file and trailing cases use identical logic.

Test plan

  • 27/27 tests pass on the branch
  • 2 new trailing-empty-line tests fail on master (0 errors reported, 1 expected)
  • 1 new test with explicit line/endLine assertions fails on master (the inverted loc bug)

Co-written by Claude.

The port was missing detection of trailing multiple empty lines at
the end of a file. Upstream handles this by adding a sentinel value
after the last non-empty line. Also matches upstream behavior of
swallowing the final trailing newline (as editors often add it).
@johanrd johanrd marked this pull request as ready for review April 13, 2026 10:29
@NullVoxPopuli NullVoxPopuli merged commit 55cd985 into ember-cli:master Apr 13, 2026
10 of 11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants