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 end-of-file-fixer
Using pip
pip install end-of-file-fixer
Usage
Basic Usage
To fix all files in the current directory and subdirectories:
end-of-file-fixer .
To check which files would be modified without making changes:
end-of-file-fixer . --check
How It Works
The end-of-file-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/community-of-python/end-of-file-fixer.git
cd end-of-file-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
Metadata
Release files for end-of-file-fixer 0.2.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| end_of_file_fixer-0.2.2.tar.gz | 3.8 kB | Without provenance | Details for end_of_file_fixer-0.2.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| end_of_file_fixer-0.2.2-py3-none-any.whl | Python 3 | none | any | Details for end_of_file_fixer-0.2.2-py3-none-any.whl |
Total release size: 8.4 kB
Release files / end_of_file_fixer-0.2.2.tar.gz
| Download URL | end_of_file_fixer-0.2.2.tar.gz |
|---|---|
| Size | 3.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
2bc0706cc08fdbd06d9a31cd12a033853793dcf502a57bbff9b4b397f39ca754
|
|
BLAKE2b-256 checksum How to use checksums |
95405b5cd990385b06c72a6fa7f651f2d7b6993b940e7333c68f28c5b0071b91
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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 / end_of_file_fixer-0.2.2-py3-none-any.whl
| Download URL | end_of_file_fixer-0.2.2-py3-none-any.whl |
|---|---|
| Size | 4.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0d0fb31841fd89a85032398e92a861d90f0f066737c8c91262096baf910f18aa
|
|
BLAKE2b-256 checksum How to use checksums |
392d18f56f7060dacac400bb6ff931063daa50e9a9c01b150cd654b7cf4f7ece
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.9.18 {"installer":{"name":"uv","version":"0.9.18","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 end-of-file-fixer 0.2.2
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.