Uncrustify (Code Beautifier) - musescore/MuseScore GitHub Wiki

Uncrustify

Uncrustify can be used to beautify your source code. In other words, Uncrustify makes sure that you follow the Code Guidelines

Download

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 of src/output.cpp

Extract

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.

Beautifying Code

Now there are three main ways to run to beautify your code:

  1. Run the Uncrustify script manually to fix the code style in your repository
  2. 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)
  3. Add it to IDE so that it beautifies your code on saving

Feel free to choose any or all of the three

Running Uncrustify Manually

To beautify this way, you can just run the script in tools/codestyle/uncrustify_run.sh, with as working directory the MuseScore folder.

Adding to Git Pre-commit hook

Copy the file in hooks/pre-commit.sh to .git/hooks/pre-commit

Adding to QtCreator

  1. Open Qt Creator
  2. Click the checkmark on Help → About Plugins → C++ → Beautifier
  3. Click close and you will be prompted to restart Qt Creator. Therefore, do so
  4. Click Edit → Preferences... → Beautifier section in the left panel
  5. Now, check Enable auto format on file save and also change the tool to Uncrustify
  6. Now go to the Uncrustify tab
  7. Put in your the path of uncrustify.exe (which is in bin in the Uncrustify folder) or simply browse it
  8. Uncheck Use file uncrustify.cfg defined in project files and now check Use file specific uncrustify.cfg and input the path of .cfg file which is located as tools/codestyle/uncrustify_musescore.cfg of the MuseScore repository (You need the whole path)

Uncrustify should now work on saving the file

Adding to VSCode

  1. Install extension "Uncrustify"
  2. Open vscode settings, and find "Uncrustify"
  3. Set Uncrustify › Config Path: path/to/MuseScore/tools/codestyle/uncrustify_musescore.cfg
  4. Find "Format"
  5. Set Editor: Format On Save on
  6. Restart VSCode

Uncrustify should now work on saving the file

⚠️ **GitHub.com Fallback** ⚠️