Skip to main content

eof-fixer

PyPI version Supported Python versions Downloads Coverage CI License GitHub stars Context7 uv Ruff ty

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.

Why this matters

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

Features

  • Automatically adds a newline to files that don't end with one
  • Removes excess trailing newlines from files that have too many
  • Respects nested .gitignore files throughout the tree to avoid processing unwanted files
  • Skip extra paths with the repeatable --exclude flag
  • Works with all text file types
  • Cross-platform compatibility (Windows, macOS, Linux)
  • Check mode (--check) to preview changes before applying them

Installation

Using uv

uv tool install eof-fixer

Or run it once without installing:

uvx eof-fixer .

Using pip

pip install eof-fixer

Usage

Basic usage

The 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 . --check

To skip extra directories on top of the defaults, pass --exclude (repeatable):

eof-fixer . --exclude node_modules --exclude dist

How it works

The eof-fixer processes files in the following way:

  1. A file with no trailing newline gets exactly one newline appended.
  2. A file with exactly one trailing newline is left unchanged.
  3. A file with multiple trailing newlines is truncated to exactly one newline.
  4. A file containing only newlines is truncated to empty.
  5. An empty file is left unchanged.

Examples

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's end-of-file-fixer. Files that already end with a single CRLF, CR, or LF are left untouched.

Configuration

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:

  • .git directories (always, not configurable)
  • .cache and .uv-cache directories (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)

Exit codes

  • 0: No files needed fixing.
  • 1: At least one file needed fixing. In --check mode 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 exits 0.
  • 2: Usage error, including a path that is not a directory.

Development

Prerequisites

  • uv for dependency management

Setup

# Clone the repository
git clone https://github.com/modern-python/eof-fixer.git
cd eof-fixer

# Install dependencies
just install

Running tests

# Run tests
just test

Linting

# Run linting and formatting
just lint

Contributing

Fork the repository, make your change on a branch, run just lint and just test, and open a pull request.

Acknowledgments

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

Part of modern-python

Browse the full list of templates and libraries in modern-python. The org profile has the categorized index.

Metadata

Release files for eof-fixer 0.5.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eof-fixer 0.5.1
File Size Uploaded Provenance Actions
eof_fixer-0.5.1.tar.gz 7.4 kB Without provenance Details for eof_fixer-0.5.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for eof-fixer 0.5.1
File Interpreter ABI Platform Actions
eof_fixer-0.5.1-py3-none-any.whl Python 3 none any Details for eof_fixer-0.5.1-py3-none-any.whl

Total release size: 15.4 kB

Release files / eof_fixer-0.5.1.tar.gz

Download URL eof_fixer-0.5.1.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
ccc7e780dfa205acabf9a717666f4076ad03b38d866bd8020a9ef076b041aff3
BLAKE2b-256 checksum
How to use checksums
7263647355f2b9e96aac52130b924d3e56bdebdbf0d2455cff96b49898f9b68b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / eof_fixer-0.5.1-py3-none-any.whl

Download URL eof_fixer-0.5.1-py3-none-any.whl
Size 7.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
927613d69224d0536b4bbf1a6e0110ea616bd60833081cd21e72fe95072f052e
BLAKE2b-256 checksum
How to use checksums
6afbc9a84da87cdace3ee0866273cb0111a57f908c069f7296774932836acbfa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.4 {"installer":{"name":"uv","version":"0.13.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for eof-fixer 0.5.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page