Skip to content

Commit

Permalink
Documentation.md: add pre-commit hook sample (fsprojects#1392)
Browse files Browse the repository at this point in the history
* Documentation.md: add pre-commit hook sample

Following https://stackoverflow.com/a/42345379/1623521

Fixes fsprojects#1207

* Add fair warning

Co-authored-by: nojaf <florian.verdonck@outlook.com>
  • Loading branch information
knocte and nojaf committed Jan 27, 2021
1 parent 7b6419a commit 138146e
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -1068,6 +1068,20 @@ Exclusion applies both to formatting and the format checking.

See [CodeFormatter.fsi](../src/Fantomas/CodeFormatter.fsi) to view the public API of Fantomas.

## A git pre-commit hook sample

A very elegant and transparent way to use Fantomas is including it in a pre-commit git hook, by creating a `.git/hooks/pre-commit` file with:

```
#!/bin/sh
git diff --cached --name-only --diff-filter=ACM -z | xargs -0 $HOME/.dotnet/tools/fantomas
git diff --cached --name-only --diff-filter=ACM -z | xargs -0 git add
```

<small>This script assumes you have installed Fantomas globally as a [dotnet tool](https://www.nuget.org/packages/fantomas-tool/)</small>

**Please use with caution** as [Fantomas is not without bugs](https://github.com/fsprojects/fantomas/issues?q=is%3Aissue+is%3Aopen+label%3A%22bug+%28soundness%29%22).

## FAKE Helpers

Fantomas also exposes some less official helper functions when formatting code in FAKE scripts.
Expand Down

0 comments on commit 138146e

Please sign in to comment.