A command-line tool that ensures all your text files end with exactly one newline character. This tool helps maintain consistent file formatting across your codebase by automatically adding or removing trailing newlines as needed.
Many POSIX systems expect text files to end with a newline character. Having consistent line endings:
- Prevents spurious diffs in version control
- Ensures proper concatenation of files
- Matches the POSIX definition of a text line
- Improves readability in terminal environments
- Automatically adds a newline to files that don't end with one
- Removes excess trailing newlines from files that have too many
- Respects nested
.gitignorefiles throughout the tree to avoid processing unwanted files - Skip extra paths with the repeatable
--excludeflag - Works with all text file types
- Cross-platform compatibility (Windows, macOS, Linux)
- Check mode (
--check) to preview changes before applying them
uv tool install eof-fixerOr run it once without installing:
uvx eof-fixer .pip install eof-fixerThe path argument must be a directory. To fix all files in the current directory and subdirectories:
eof-fixer .To check which files would be modified without making changes:
eof-fixer . --checkTo skip extra directories on top of the defaults, pass --exclude (repeatable):
eof-fixer . --exclude node_modules --exclude distThe eof-fixer processes files in the following way:
- A file with no trailing newline gets exactly one newline appended.
- A file with exactly one trailing newline is left unchanged.
- A file with multiple trailing newlines is truncated to exactly one newline.
- A file containing only newlines is truncated to empty.
- An empty file is left unchanged.
| Original file content | After processing |
|---|---|
hello world |
hello world\n |
hello world\n |
hello world\n |
hello world\n\n\n |
hello world\n |
\n\n\n |
(empty file) |
| (empty file) | (unchanged) |
Note on line endings: when appending a missing terminator, eof-fixer always writes an LF (
\n), regardless of the existing line-ending style of the file. A file that otherwise uses CRLF or CR will end up with a mixed terminator on its last line. This matches the behavior of pre-commit'send-of-file-fixer. Files that already end with a single CRLF, CR, or LF are left untouched.
The tool respects your .gitignore files, so it won't process files that are ignored by Git. It honors the full nested convention: the .gitignore at the root and any .gitignore files in subdirectories, with Git precedence: deeper files override shallower ones, and ! negations re-include. Ignore resolution is pure-filesystem: .git/info/exclude and the global core.excludesFile are not consulted, and Git itself is never invoked, so the tool works on any directory, repository or not.
It also skips:
.gitdirectories (always, not configurable).cacheand.uv-cachedirectories (used by uv) by default; pass--exclude DIR(repeatable) to add more names to skip on top of these- Binary files (detected by null bytes in the first 1024 bytes)
0: No files needed fixing.1: At least one file needed fixing. In--checkmode no changes are written; in the default (fix) mode the files have been rewritten in place. The non-zero exit in fix mode is intentional so the tool can be used as a CI gate. A second run exits0.2: Usage error, including a path that is not a directory.
- uv for dependency management
# Clone the repository
git clone https://github.com/modern-python/eof-fixer.git
cd eof-fixer
# Install dependencies
just install# Run tests
just test# Run linting and formatting
just lintFork the repository, make your change on a branch, run just lint and just test, and open a pull request.
The core file-fixing logic in this project is derived from the
end-of-file-fixer
hook in pre-commit/pre-commit-hooks,
which is also distributed under the MIT License. This project repackages that
logic as a standalone CLI with .gitignore-aware directory traversal so it can
be used outside of the pre-commit framework.
- pre-commit - A framework for managing and maintaining multi-language pre-commit hooks
- editorconfig - Helps maintain consistent coding styles across different editors and IDEs
π¦ PyPI
π License
Browse the full list of templates and libraries in
modern-python. The org profile has the categorized index.