Skip to content

Uncrustifying

aljelly edited this page Nov 17, 2018 · 8 revisions

This page is kept for reference, we'd prefer if anyone wanting to contribute manually formats code according to elementary's code style.

Installing uncrustify

To easily install uncrustify 0.65, run the following in the terminal:

cd ~/Downloads # or wherever you want it
wget https://github.com/uncrustify/uncrustify/archive/uncrustify-0.65.tar.gz
tar -xf uncrustify-0.65.tar.gz
cd uncrustify-uncrustify-0.65/cmake/
cmake ..
sudo make install

Test it with uncrustify --version. It should output Uncrustify-0.65_f.

Using uncrustify

Setup automatic uncrustifying

The pre-commit hook runs uncrustify for you automatically when you commit. This removes the need to manually run it.

To set it up, simply run these commands from the base repository folder:

cp pre-commit .git/hooks/
chmod +x .git/hooks/pre-commit

uncrustify should now run automatically when you commit.

Manually running uncrustify

The above pre-commit hook should remove the need to run it manually. But if you need to for some reason, navigate to src/ and run uncrustify like this:

uncrustify --replace --no-backup -c ../etc/uncrustify-elementary-vala.cfg */*.vala *.vala

Run uncrustify on the code with the above command before you commit your changes! This helps keeps the commit noise down.

Important note

Make sure you don't end comment lines with a \ (backslash)!

Otherwise uncrustify turns the next line into a comment as well:

// This prints a \
my_function ();
// This prints a
// my_function ();

It's okay if you put any character after it though:

// This prints a \ character.
// (or) This prints a \.
my_function ();

Clone this wiki locally