Hot to linter basic things like trailing whitespaces and newlines
Fortunately, solution already exists, though not really obvious.
Lets start with project called EditorConfig. It allows you easily define and maintain consistent coding styles between different editors and IDEs. You just need to install extension for your editor, for example EditorConfig for VS Code, and keep in repository file with the name
.editorconfig which looks like this:
trim_trailing_whitespace = true
insert_final_newline = true
It will ensure that all trailing whitespaces will be removed from file on saving. As well as final newline will be added.
But how to add linter for these things?
Just add to your CI/pre-commit-webhook/etc this utility — editorconfig-checker. It will read rules from
.editorconfig and fail if files in repo don’t pass them.