Small utility to ensure files end with one newline.
Project description
End of file
End of file is formatter to ensure text files always end with one newline. Eof is able to resolve every possible situation - missing newline, more then one newline and whitespaces mixed with newlines. Simple configuration is done using parameters, no config file is needed.
Configurable options:
- include or exclude hidden files (file or folders starting with dot)
- blacklisted strings that are found inside traversed paths
- whitelisted extensions
- whitelisted files that are registered with git
- identification of text files (mimetype or bruteforce)
- validation only mode for ci pipelines
The code is short and dead simple so if you have more questions feel free to open an issue or take a look into src.
Installation
End_of_file is python script and thus python3.6 or newer must be present on the system. Eof is just another pip package and can be installed with pip install end-of-file
.
Usage
Installation adds Eof to your environment so feel free to try
eof --help
To format project
eof ./project
If you are using git and are concerned only about files that are registered to git following flag can be used. Git must be installed for this option to work.
eof ./project --git
To format only specific extensions
eof ./project --extensions=txt,md,py,rb,cpp
To check in ci/cd if project is formatted correctly, return 0 if yes, 1 if changes are needed. Files are not changed.
eof ./project --check
In case you have for example build destination in your project and want to skip it you can use --ignore flag. Paths with substring from this option are skipped.
eof --ignore /dist -i egg-info
Circleci job example
circleci-job:
docker:
- image: circleci/python:3
steps:
- checkout
- run: pip install end-of-file
- run: eof --check
Strategies
Eof needs to have a way to identify files that should be checked for correct newline. There are two options to choose from.
Bruteforce (default)
Bruteforce strategy just opens the file and tries to read first line, if that does not work it assumes the file does not contain text and is skipped. This should be the most precise but may take more time.
eof --strategy='bruteforce'
Mimetype
Mimetype strategy checks extensions against lookup table.
eof --strategy='mimetype'
Testing
Code is fairly well tested, feel free to take a look.
License
BSD 3-Clause
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
Built Distribution
File details
Details for the file end-of-file-1.1.0.tar.gz
.
File metadata
- Download URL: end-of-file-1.1.0.tar.gz
- Upload date:
- Size: 5.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2274efef7f1bf3d57325e16989058a57cf77e04a926d7397d04906cacce52e6 |
|
MD5 | ab981710c2b21bbbaa74eb61a28f7057 |
|
BLAKE2b-256 | f2e10717e44720f71353957d9b701cad571827f066896d2bda117233ae43af58 |
File details
Details for the file end_of_file-1.1.0-py3-none-any.whl
.
File metadata
- Download URL: end_of_file-1.1.0-py3-none-any.whl
- Upload date:
- Size: 5.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.61.1 CPython/3.9.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 30579a7c1560307127f6826a6695d16a5d1f601203a8bfd271707d35b4adff77 |
|
MD5 | 86d1e633749e6031b3e7f5813b1211d9 |
|
BLAKE2b-256 | 17b20d012f198815a2ab95794d386d1f50b36a6eced97c394f0e881657bd2ad4 |