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
  • Satisfies POSIX compliance
  • 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 add eof-fixer

Using pip

pip install eof-fixer

Usage

Basic Usage

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. Files with no trailing newline: Adds exactly one newline at the end
  2. Files with exactly one trailing newline: Leaves unchanged
  3. Files with multiple trailing newlines: Truncates to exactly one newline
  4. Empty files: 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
`` (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 standard 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.

Additionally, it always 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 pre-commit or CI gate — re-run after the fix and the exit code returns to 0.

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

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

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

📦 PyPI

📝 License

Part of modern-python

Browse the full list of templates and libraries in modern-python — see the org profile for the categorized index.

Metadata

Release files for eof-fixer 0.4.3

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.4.3
File Size Uploaded
eof_fixer-0.4.3.tar.gz 7.1 kB Details

Built distribution (wheel)

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

Total release size: 15.2 kB

Release files / eof_fixer-0.4.3.tar.gz

Download URL eof_fixer-0.4.3.tar.gz
Size 7.1 kB
Tags Source
SHA-256 checksum
How to use checksums
45801a2f1ac3ba37955efadecff182996925655f16bd620de729b4321c0bb87c
BLAKE2b-256 checksum
How to use checksums
f41d6e3d4b7d9fff6c26304a14d1621271325d9376b206f0456e913e6cdc4eab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","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.4.3-py3-none-any.whl

Download URL eof_fixer-0.4.3-py3-none-any.whl
Size 8.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
64813529d79894b6f12fa25d7f62fd70ea00e35eb1a7c5418c401917b01393e8
BLAKE2b-256 checksum
How to use checksums
24ca425689e42c31bdeeb745abc4e189898839cc03d712764efe97628308312f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.12.17 {"installer":{"name":"uv","version":"0.12.17","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 history Release notifications | RSS feed

0.5.0

2 release files

This release

0.4.3 This release

2 release files

0.4.2

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.2

2 release files

0.3.1

2 release files

0.3.0

2 release files

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