Uncrustify (Code Beautifier) - musescore/MuseScore GitHub Wiki
Uncrustify can be used to beautify your source code. In other words, Uncrustify makes sure that you follow the Code Guidelines
Something to note is that you are supposed to use only Uncrustify v0.73
- For Windows, you can download Uncrustify from here
- For Linux, even though you can download it using
apt-get
, it might not offer v0.73. Therefore, you might have to download it from here - Or just download source code (https://github.com/uncrustify/uncrustify/releases/tag/uncrustify-0.73.0) and build (instruction). It's very easy to do
- Note there is a potential bug in Uncrustify 0.73 when building on MacOS. If you're getting build errors relating to
std::map
, it is likely you need to move#include <map>
outside the WIN32#ifdef
at the top ofsrc/output.cpp
After extracting the contents, you would want to move it to a better place, say Program Files (if you are on Windows)
And add the path of uncrustify to PATH environment.
Now there are three main ways to run to beautify your code:
- Run the Uncrustify script manually to fix the code style in your repository
- Add it to your Git Pre-commit hook, so that your changed files will be fixed up just before you commit (that way, you really never have to think about it)
- Add it to IDE so that it beautifies your code on saving
Feel free to choose any or all of the three
To beautify this way, you can just run the script in tools/codestyle/uncrustify_run.sh
, with as working directory the MuseScore folder.
Copy the file in hooks/pre-commit.sh
to .git/hooks/pre-commit
- Open Qt Creator
- Click the checkmark on Help → About Plugins → C++ → Beautifier
- Click close and you will be prompted to restart Qt Creator. Therefore, do so
- Click Edit → Preferences... → Beautifier section in the left panel
- Now, check
Enable auto format on file save
and also change the tool to Uncrustify - Now go to the Uncrustify tab
- Put in your the path of uncrustify.exe (which is in bin in the Uncrustify folder) or simply browse it
- Uncheck
Use file uncrustify.cfg defined in project files
and now checkUse file specific uncrustify.cfg
and input the path of .cfg file which is located astools/codestyle/uncrustify_musescore.cfg
of the MuseScore repository (You need the whole path)
Uncrustify should now work on saving the file
- Install extension "Uncrustify"
- Open vscode settings, and find "Uncrustify"
- Set
Uncrustify › Config Path:
path/to/MuseScore/tools/codestyle/uncrustify_musescore.cfg
- Find "Format"
- Set
Editor: Format On Save
on - Restart VSCode
Uncrustify should now work on saving the file