mne-cpp icon indicating copy to clipboard operation
mne-cpp copied to clipboard

Introduce tool for consistent formatting

Open LorenzE opened this issue 2 years ago • 7 comments

I think it would be worth taking a look at a tool guaranteeing consistent formatting such as: https://clang.llvm.org/docs/ClangFormat.html. You can integrate it into QtCreator and VSStudio, see https://doc.qt.io/qtcreator/creator-beautifier.html.

LorenzE avatar Dec 06 '22 20:12 LorenzE

I agree. Now the rules... my man. We need to agree on which rules make the code beautiful.

😄 just joking. I'm sure we'll agree pretty easily. 😮

juangpc avatar Dec 06 '22 20:12 juangpc

I do not really mind about the rules, just that it is consistent and therefore easier to read :)

LorenzE avatar Dec 06 '22 20:12 LorenzE

We could even think about forcing a format run every time we push to main? https://ivanludvig.github.io/blog/2020/07/05/clang-fromat-github-action.html

LorenzE avatar Dec 06 '22 21:12 LorenzE

I like that. But instead of relying on the github actions. Could you find out the actual command it runs so that we can run it locally the same way it would run in github's runners?

juangpc avatar Dec 06 '22 21:12 juangpc

@juangpc I gave clang-format a try. It was straight forward to use and install. Once installed you can do the following from your cmd line:

clang-format -style=LLVM -i connectivity.h // This will format the file in place
clang-format -style=LLVM connectivity.h > connectivity_formatted.h // This will create a new formatted file
clang-format -style=LLVM connectivity.h // This will output the formatted file to the cmd line

Integrating it to QtCreator and activate "on save formatting" was easy as well, see this guide https://doc.qt.io/qtcreator/creator-beautifier.html. Once the CMake integration is done, we will of course be able to use other IDEs as well. Most of them support clang-format.

I used the built in style LLVM, which I think would serve as a good basis for our project. Individualised styles are of course supported and can be put into a clang-format file, which could be added to the git repository.

@juangpc @gabrielbmotta Maybe you can give it a try on your side to get a feeling for some good style configs? What do you think?

LorenzE avatar Dec 09 '22 21:12 LorenzE

the way to go. 👍🏻

juangpc avatar Dec 09 '22 23:12 juangpc

Formatting recursively can be achieved via (on Mac/Linux):

find . -iname '*.h' -o -iname '*.cpp' | xargs clang-format -style=LLVM -i

I started some clean up work here https://github.com/LorenzE/mne-cpp/tree/feature/formatting. Still WIP but please have a look and tell me what you think. I also started to remove some preamble stuff. Still have to make it build again and revert the changes to the eigen library.

Once there is a consensus on which formatting to use I can do a final pass over the cleaned up files.

LorenzE avatar Dec 13 '22 23:12 LorenzE