Search code examples
gitclojurediffwhitespacecode-formatting

Formatting Clojure code in a multi-editor team


As our Clojure team grows we're seeing more and more editors in use. This is causing a lot of extraneous whitespace changes.

My biggest concern isn't really about how the code is formatted--all the editors produce readable code--it's more about git blame turning quite unusable as every line in the project gets its history inflated by uninteresting changes to formatting.

In solving this problem the two top contenders right now is to use cljfmt prior to committing and/or a script that removes whitespace changes from git's changeset.

How is everyone else handling this?


Solution

  • git blame turning quite unusable as every line in the project gets its history inflated by uninteresting changes to formatting.

    Not only that, it can also lead to unnecessary conflicts. Using a formatting tool (cljfmt as you mentioned) in the pre-commit hook can help to reduce this issue. The pre-commit hook could be made active (re-format the files and commit) or passive (abort commit if there is a formatting issue).

    Also consider using EditorConfig, with which you can set up formatting rules and then track the configuration file together with the project. Some IDEs and editors have integrated support for EditorConfig, many others have a plugin available.