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
- Satisfies POSIX compliance
- 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
.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
uv add end-of-file-fixerpip install end-of-file-fixerTo 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 . --checkThe 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
| 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) |
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)
0: No files needed fixing or all files were successfully fixed1: Some files needed fixing (when using--checkmode)
- uv for dependency management
# 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# Run tests
just test# Run linting and formatting
just lintContributions 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
This project is licensed under the MIT License - see the LICENSE file for details.
- pre-commit - A framework for managing and maintaining multi-language pre-commit hooks
- editorconfig - Helps maintain consistent coding styles across different editors and IDEs