Fork me on GitHub

What do you guys use within a project to have consistent formatting? cljfmt looks like the standard way to go & integrates nicely with vim & CIDER. We’re creating our first (yay!) collaborative Clojure projects now and noticed that our setups aren’t quite compatible. If I saved my co-workers file using my setup it would automatically fix (as in cljfmt fix) the file. We’re looking to reach a consensus, open to everything, so I’m hoping you guys can share your experiences. simple_smile


@mull: This is not clojure specific, but the usual way to go is to format the code as part of the pre commit job, if your build chain allows that. Another solution is to autoformat on save if the editor supports this option.


@sveri: auto format on save is what I would go for as well. Pre-commit is an interesting idea. From my vim-cljfmt it sometimes screws things up though so I can imagine it could get a bit messy


@mull: I never tested it for cljfmt, but, if I was serious on it in a team environment I would take my time and try to make it work reliably. That's what our team does for java code formatting, we solved it by having an installchain containing eclipse and the same format settings enabled for everyone on file save. So there are different solutions, just make sure they work reliable for everyone to reduce developer pain.


@sveri: thanks for your input, we appreciate it simple_smile


@mill yw, be creative, I am sure you find something simple_smile


@mull we eventually gave up on getting emacs/vim/cursive to all play together nicely. We eventually settled on just using 2-indents for everything.


Emacs has it's own list of "special" 1-indents, and clojure-static has it's list, no idea how cursive determines it.


It just ends up messy.


2-char indent, everywhere. Simple and understandable.


@dominicm: Makes sense. Though 2-char indent everywhere doesn’t end up as pretty :’)


In most cases you don't notice the 1v2 difference. Or is there something I've missed?


Oh, we align if there is an argument on the first line.


I was talking about indenting macros with 1 space, and fns with 2 spaces.


Otherwise that's too ugly! 😛


@mull I created this so you can do fast pre-commit hooks.


@snoe you've really solved the general tooling problem by using js. It's really cool.


@snoe: I know its open source and all, but why not make a leiningen task / plugin or some kind of a jar? Having to install nodejs for formatting clojure code is strange 😄 Well, I dont want to criticize you. Always nice to see stuff given back to the community. Just wondering about so many people going nodejs today.


simply for speed, there's if you want a plugin


I think asking that question about node but not about java is a historical accident. simple_smile troll


@snoe: Ah, awesome. Is it so much slower compared to clojure?


Aehm, compared to node I mean


for a commit hook, I was super frustrated with starting up jvm and clojure on each commit (and a repl call wouldn't work on our team) it's 2-3 seconds of wait. the startup time for cljs is basically instant.


Got it and I have to agree, having to wait for every commit sucks.