Skip to main content

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 .gitignore patterns 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:

  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)

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:

  • .git directories
  • .cache directories (used by uv)

Exit Codes

  • 0: No files needed fixing or all files were successfully fixed
  • 1: Some files needed fixing (when using --check mode)

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.

  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.

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

end_of_file_fixer-0.2.1.tar.gz (3.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

end_of_file_fixer-0.2.1-py3-none-any.whl (4.6 kB view details)

Uploaded Python 3

File details

Details for the file end_of_file_fixer-0.2.1.tar.gz.

File metadata

  • Download URL: end_of_file_fixer-0.2.1.tar.gz
  • Upload date:
  • Size: 3.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","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

Hashes for end_of_file_fixer-0.2.1.tar.gz
Algorithm Hash digest
SHA256 1614ec17976fb30748e0eb67403192fd318fd8e5958919f59d1a94e944cfeb91
MD5 4d4bd399efe0e4727107cbc5efafc9c7
BLAKE2b-256 8546a432e31142f81ce53044c6389cf73f4bb1c02dce6b332c96b9b7c4df72e7

See more details on using hashes here.

File details

Details for the file end_of_file_fixer-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: end_of_file_fixer-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 4.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.15 {"installer":{"name":"uv","version":"0.9.15","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

Hashes for end_of_file_fixer-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b8f4e1224fce6600767f40f11be17f4b872352f9f37ec2dcbdcf9adb6baf8ed7
MD5 4bbf9d83051ffa4aea32685c18ba13f0
BLAKE2b-256 9a4c331f5f376cbe842f70037773ab6f2186747a9afefe37c406f3017a23d2d4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page