Settings

Theme

Show HN: EOF Script to ensure text files end with newline

github.com

2 points by Keeo 5 years ago · 3 comments

Reader

KeeoOP 5 years ago

I do quite a lot of code reviews and usually all the files contain newline at the end - so github is happy and does not show warning icon. But sometimes - new person joins the project and is not aware of this, or somebody does small change in misconfigured ide or file is generated and in these cases newline is missing. My original way of handling this was to just edit the file directly but then I would have to wait for tests to run again, so at the end I gave up. Linters can usually help but they are always tied to one type of text files and do not cover config files.

I wanted to write a simple python script that will go through all text files (with white and blacklist) and ensures there is exactly one newline at the end. I also wanted for script to be able to fix the file or just report issues.

The current version works quite well - atleast for my 1 day of limited testing. Please take a look and happy to hear what you think.

pestatije 5 years ago

What's the problem? Why is github showing a warning?

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection