tweag / ormolu

A formatter for Haskell source code
https://ormolu-live.tweag.io
Other
958 stars 83 forks source link

Formatting in pre-commit hook vs CI #703

Closed Martinsos closed 3 years ago

Martinsos commented 3 years ago

Hi, you recommended to do formatting in CI and you pointed to a github action for that.

What about pre-commit hooks -> do you have any advice on that? It would be great to get some opinionated advice on this -> do you recommend using a pre-commit hook, and should it check for formatting or actually perform it?

mrkkrp commented 3 years ago

Personally, I haven't found a use for pre-commit hooks yet. When I commit I don't want anything extra to happen, especially if it can fail or corrupt my files. Even though Ormolu is fairly robust these days, it does have bugs, so I'd be cautious about using it in commit hooks. On the other hand, checking formatting on CI guarantees that your code stays formatted without performing any transformations, which I believe always should be triggered explicitly by the user.

Martinsos commented 3 years ago

Thanks @mrkkrp, that makes sense - especially not doing formatting in the pre-commit hooks. However we could do a check in the pre-commit hook, just to avoid having it fail during CI since that is more expensive -> but on the other hand, once you get ormolu set up in the editor, you will more or less never encounter that situation, and still we have check in the CI as a gatekeeper.

Ok, that does it for me, thanks!