Skip to main content
Enforces a newline at the end of non-empty files.

Description

POSIX defines a line as a sequence of characters ending with a newline. Files that lack a trailing newline can cause issues with file concatenation, produce messy diffs in version control, and interfere with shell prompts when printed with cat. This rule enforces (or prohibits) a final newline in Dockerfiles, mirroring ESLint’s eol-last rule. In the default "always" mode, the rule reports a violation when a non-empty file does not end with \n. In "never" mode, it reports when a file does end with \n. Empty files (zero bytes) are always ignored.

Companion editor configuration

Use EditorConfig integration to configure IDEs and editors to insert the final newline before tally reports it.

Examples

Bad (mode: “always”)

(where marks the end of file with no trailing newline)

Good (mode: “always”)

Configuration

Default (no config needed):
Disable the rule:
Require files to not end with a newline:

Options

Auto-fix

This rule provides a safe auto-fix:
  • In "always" mode, a missing final newline is appended.
  • In "never" mode, the trailing newline is removed.