Open suamor opened 4 years ago
I don't care whether we use spaces or tabs, just that it's consistent throughout the code and that we use one of the "beautifiers" for our code. Maybe this issue should be named "integrate code beautifier"?
So I will use clang-format as tool for formatting. As this tool does not support recursion I use some bash recursive glob trick to achieve this: https://unix.stackexchange.com/questions/49913/recursive-glob
$ shopt -s globstar
$ clang-format -i -style=WebKit **/*.cpp **/*.h
For cmake files we can use https://github.com/cheshirekow/cmake_format
pip install cmake_format
cmake-format -c canorus-cmake-format.yaml
For python code yapf can be used. We do not manually edit ui (xml) files, but other files may need to be formatted as well (please add which ones).
Config file is below (github does not support upload of yaml files)
Does cmake support clang-format? Ideally you would run something like make fmt
. At least the fmt
command is common for golang and rust environments.
Ok, I checked the web, but nothing obvious exists for this. IMO we should make a new fmt
target in CMakeLists.txt which runs the clang-format
on all the sources. Since the sources are provided in CMakeLists.txt anyway, there is no need for any other scripts.
Also, this should be part of CI checks, i.e. that all committed files are formatted before merging into master.
Does cmake support clang-format? Ideally you would run something like
make fmt
. At least thefmt
command is common for golang and rust environments.
Above works fine and code looks good as well. So in the first part will create commit for with formatting changes after first run. Major change is include sequence which has some kind of hierarchy and sorted alphabetically. No build issues encountered. canorus.cpp and pyconsole.cpp needed to have their python include in first position. If we want to have an automatic formatting all the time this case has to be taken car of.
https://github.com/canorusmusic/canorus/pull/135 -> merged Also contains style files (unmodified)
ToDo: Styling of CMakeLists.txt Integration in Travis Adaption of Style
I have many years of experience in software developmen (C++, Python, QML and more). In projects I was involved in using of tabs was either always discouraged, not allowed, automatically converted to spaced with git/svn or (many years ago) used in consence after issues using both.
There are advantages using tabs over spaces, mainly that everyone can set his own preferred tab size. However in my experience especially this makes things worse than better.
Example: https://github.com/canorusmusic/canorus/blob/master/src/layout/layoutengine.cpp
You see that the code stretches beyond editor width. I have no influence on the horrible github layout which looks so much like 1980's cheap UI. But at least I can use spaces to have more code in one line visible by using spaces.
Fun facts: https://stackoverflow.blog/2017/06/15/developers-use-spaces-make-money-use-tabs/
Switching to spaces can be done with tools automatically.