Strip Trailing Whitespace from Git projects


πŸŽ„This post has fully grown

A common linting error thrown by various linters is for trailing whitespace. I most often use flake8. I generally have [pre-commit]( hooks setup to strip this, but sometimes I run into situations where I jump into a project without it, and my editor lights up with errors. A simple fix is to run this one-liner.

One-Liner to strip whitespace


git grep -I --name-only -z -e '' | xargs -0 sed -i -e 's/[ \t]\+\(\r\?\)$/\1/'

pre-commit article

read more about pre-commit here.

πŸ‘€ see an issue, edit this post on GitHub

If you found value in this post
and want to send a tip.

Buy Me A Coffee

tweet about this post and it will show up here.

←An IndieWeb Webring πŸ•ΈπŸ’β†’