If you use LLM coding agents, I'm sure you dealt with random empty spaces in your codebase
The solution is simple: add a pre-commit hook to your project
No custom rules to spend your tokens, no extra steps necessary. Just set and forget
- Navigate to your project. Keep in mind it needs to be a git repo.
- Open the folder
.git/hooks - Create a file named
pre-commit - Paste the code below
#!/bin/bash
# Remove trailing whitespace from staged files
for file in $(git diff --cached --name-only --diff-filter=ACM); do
if [ -f "$file" ]; then
sed -i 's/[[:space:]]*$//' "$file"
git add "$file"
fi
done
exit 0- Set the permissions by running the following command in your terminal (same folder as your git repo).
chmod +x .git/hooks/pre-commitDONE! From now on, git will automatically get rid of it for you at every commit.
- This assumes you have
sedandgitinstalled. If you're are using Windows, make sure Git Bash is installed. - Follow me on Twitter/X https://x.com/nathabonfim59