Emacs - there’s a plugin/script called google-c-style. You can find it here or just install from MELPA.
Spacemacs - you can add google-c-style to dotspacemacs-additional-packages.
Vim- check out https://github.com/google/vim-codefmt
Git hook
There is a pre-commit hook in hooks/pre-commit, and if you run bash hooks/install_hooks.sh it will be installed for you. Going forward, it will run clang-format -i (which implicitly uses the .clang-format file in the repo) on any changed files to format them. If you need to disable this for some reason (though your tests will fail if you haven’t formatted things correctly) you can use git commit --no-verify.
I think yes. Perhaps give the main devs on each repo a chance to evaluate?
I’m not 100% sure that changing the whitespace in the Stan repo will be ok, but it’s a quick(ish) check. I thought some of the funky whitespace was due to compiler bugs / behavior with most vexing parse or maybe something else. I’d also like to get @Bob_Carpenter’s take on the automatically formatted code after it’s applied to the compiler. I wouldn’t be surprised if there are minor tweaks to make to the formatting rules more palatable.
A cpplint error just came up on Yi’s pull request because of a missing include in a test file. Will the reformatting test for missing includes? Do we care? We have header tests that will test independent compilability.
No, clang-format doesn’t test for missing includes. We should probably also keep cpplint around for that and whatever else it does in addition to formatting stuff (hard to actually find a list anywhere).
Weird, mine, also on mac but installed through homebrew, claims to also be version 5.0: clang-format version 5.0.0 (tags/google/stable/2017-06-22). I could remove the problem key from the file - just one formatting rule we’d have to follow by hand.
I removed the problem key on develop. I’ve been updating the wiki with instructions and whatnot and keeping that up-to-date as the authoritative store of the information about auto-formatting and style. The latest addition is an instruction to install a specific version of clang-format for Mac so we don’t have any inconsistencies.
Jenkins now tests with this specific version, though I need to get the correct version installed on the master node which homebrew doesn’t support anymore…
Just did my first bit of clang-formatting. I was skeptical, but this is awesome! I can just type out comments/code however I want and then the formatter fixes them! No worrying about rearranging code to fit on 80 lines anymore.
[ClangFormat] test/unit/math/fwd/scal/fun/gamma_p_test.cpp is not formatted correctly according to clang-format
[ClangFormat] test/unit/math/prim/scal/fun/grad_reg_lower_inc_gamma_test.cpp is not formatted correctly according to clang-format
My local version is:
krzysztof@hagrid:~$ clang-format --version
clang-format version 5.0.1-svn319952-1~exp1 (branches/release_50)
I was going to look into installing the specific tag (google/stable) from source but it’s a beastly download and I haven’t looked up how to get the right tag using csv yet, I think I know how from the git mirror.
All the usual suspects! Versioning. Floating point. Everyone working on different OS-es. C++'s spec that leaves way too much to the compiler writer’s discretion. Moving targets as C++ and the library dependencies change.
Every dependency just adds that much work. Everyone says each one’s easy, but they add up and eventually we hit the limit where all of our time is spent on maintenance. This is why I’ve been so against adding dependencies beyond Boost and Eigen. Even so, it’s been a nightmare keeping up.