Auto-tidying
Jul. 15th, 2023 12:07 pm![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
So we've required files to be tidied using
Here's the perl variant of the script:
This also has the bonus that it only tidies files you added to your commit, so you don't end up with rogue changes in files you didn't touch because someone else forgot to tidy before a branch got merged!
EDIT:
kareila rightfully pointed out that I didn't actually specify the install instructions (they're in the linked Prettier docs but, uh, that's not that intuitive). This script should go in the file
perltidy
since 2019, buuuuut I am terrible at remembering to manually do it, so! I threw together a quick'n'dirty way of automatically running tidy on commit. It's based on this example from the Prettier docs (Prettier is like perltidy but for CSS/JS/HTML).Here's the perl variant of the script:
#!/bin/sh FILES=$(git diff --cached --name-only --diff-filter=ACMR | sed 's| |\\ |g') [ -z "$FILES" ] && exit 0 # Prettify all selected files echo "$FILES" | xargs tidyall # Add back the modified/prettified files to staging echo "$FILES" | xargs git add exit 0
This also has the bonus that it only tidies files you added to your commit, so you don't end up with rogue changes in files you didn't touch because someone else forgot to tidy before a branch got merged!
EDIT:
![[personal profile]](https://www.dreamwidth.org/img/silk/identity/user.png)
.git/hooks/pre-commit
, and that file needs to be executable, which you can do on the commandline by running chmod +x .git/hooks/pre-commit