-
-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Format in pre-commit hook #1207
Comments
@rastreus this seems to work for me (on Windows): #!/bin/sh
FILES=$(git diff --cached --name-only --diff-filter=ACMR "*.fs" "*.fsx" | sed 's| |\\ |g')
[ -z "$FILES" ] && exit 0
# Format all selected files
echo "$FILES" | xargs dotnet fantomas
# Add back the modified/prettified files to staging
echo "$FILES" | xargs git add
exit 0 I stole some code from other places so I can't really explain each line 😅, but the |
@nojaf i wrote something very similar to this once to take the diff and pass only those files with changes to the shopify cli for deployment. Basically: Line 1 gets the changed files filtering the git diff to what your after I thinK the way to to this in a more automated way will be to create a git hook that runs the lines 1 and 2 of your script as a ‘pre-commit hook’. That should do it. |
Hey @agentlewis, this is the content of the |
* Documentation.md: add pre-commit hook sample Following https://stackoverflow.com/a/42345379/1623521 Fixes #1207 * Add fair warning Co-authored-by: nojaf <[email protected]>
As mentioned in https://twitter.com/rastreus/status/1321296796124143617?s=20, how can Fantomas be used as a precommit hook?
On top of my head I think the local dotnet tool can be used for this. However, as I find this a good question we should write something out in the documentation to explain this.
Also mention in the docs that
.fantomasignore
file exist in case Fantomas is not able to format the file for some reason.The text was updated successfully, but these errors were encountered: