We have switched from a custom, manually enforced style guide to using the clang-format tool. Our automated testing now fails with an error for pull requests that don't conform to the new clang-format style - it prints out a diff/patch of the changes necessary to conform with our coding style.

Formatting Your Code

You will need to have clang 3.9 or later installed. If your clang install is from the MOOSE environment package (i.e. the ones downloadable via the links on http://mooseframework.org/getting-started/) and you use Linux, you may need to upgrade to the newest MOOSE environment package version in order for clang-format to be available in your PATH. Many text editors have plugins and support for automatically running clang-format on the files you edit. We recommend using those. For example:

If you wish, you can also install a pre-commit hook that will prevent you from committing changes that don't comply with the new style. To install this hook, run the scripts/install-format-hook.sh script in the MOOSE repository.

You can manually run git clang-format [<commit>] to automatically format files changed since <commit> (or HEAD if omitted). You can also run clang-format -i [<file>...] to update the desired files. We recommend making sure your files comply with the clang-format style on every commit.

Updating In-flight Changes

Changes (pull requests, branches, etc.) that were started before we reformatted our codebase will have a lot of conflicts when attempting to merge into or rebase with the new mainline code. We have provided some tools to aid in this process. First you will need to install a custom git configuration by running (in the main MOOSE repo):

./scripts/install-clang-format-merge-hook

Then make sure ./scripts/clang_format_merge_driver is in your PATH.
To rebase a branch onto the newly formatted MOOSE mainline devel branch run the rebase command like normal, e.g.:

If you enter anything in this field your comment will be treated as spam

Cody
6 months, 4 weeks ago

Andy,

I had the same problem at first. The problem was that I had another before-save-hook active lower in my .emacs file to remove trailing whitespace on save. I'm not sure why that mattered but I moved that up above this new configuration and the over-aggressive behavior went away. It doesn't make any sense by that would be the case but it fixed it. Check and see if you have any other active hooks.

If you enter anything in this field your comment will be treated as spam

AlexL
6 months ago

I get the same undesirable behavior as Andy (haven't tried his fix yet) when putting the clang-formatting logic at the bottom of my .emacs and saving even a .gitignore file in a totally different directory! I'm bamboozled for a variety of reasons...shouldn't this just be a c++ mode save-hook? And shouldn't that lisp logic be matching against the MOOSE path such that I shouldn't see this if I'm in a totally different directory?? Weird.