A command-line tool that ensures all your text files end with exactly one newline character
Project description
End Of File Fixer
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
.gitignorepatterns to avoid processing unwanted files - Works with all text file types
- Cross-platform compatibility (Windows, macOS, Linux)
- Dry-run mode 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
How It Works
The eof-fixer processes files in the following way:
- Files with no trailing newline: Adds exactly one newline at the end
- Files with exactly one trailing newline: Leaves unchanged
- Files with multiple trailing newlines: Truncates to exactly one newline
- 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) |
Configuration
The tool automatically respects patterns in your .gitignore file, so it won't process files that are ignored by Git. Additionally, it always ignores:
.gitdirectories.cachedirectories (used by uv)
Exit Codes
0: No files needed fixing or all files were successfully fixed1: Some files needed fixing (when using--checkmode)
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.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some amazing feature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
This project is licensed under the MIT License - see the LICENSE file for details.
Related Projects
- pre-commit - A framework for managing and maintaining multi-language pre-commit hooks
- editorconfig - Helps maintain consistent coding styles across different editors and IDEs
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file eof_fixer-0.3.1.tar.gz.
File metadata
- Download URL: eof_fixer-0.3.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
146cfdff41df7c3cc6aa3432a78d9e580e835627b93974e1fa2be0ef8556b267
|
|
| MD5 |
537c626503566b76d971dcd72d121785
|
|
| BLAKE2b-256 |
004a458973e36f95649a6dcf78193c99f6a675ab391a6a4d8930dc17175413d0
|
File details
Details for the file eof_fixer-0.3.1-py3-none-any.whl.
File metadata
- Download URL: eof_fixer-0.3.1-py3-none-any.whl
- Upload date:
- Size: 4.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.10.10 {"installer":{"name":"uv","version":"0.10.10","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}
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
df5030207cfd053cf156d64a1408962afa2b7e3234ed6bcdb06f3f222cb22863
|
|
| MD5 |
53d4977b2a65c6010d43ad7fa140981c
|
|
| BLAKE2b-256 |
a1c596a10fa5caf5ed27bb76e954353f796fbce1b3768caa431e297b5959c3c0
|