SkillAgentSearch skills...

Uncrustify

Code beautifier

Install / Use

/learn @uncrustify/Uncrustify
About this skill

Quality Score

0/100

Supported Platforms

Universal

README

Coverage Status <a href="#"><img src="https://img.shields.io/badge/C++-11-blue.svg?style=flat-square"></a> Conan Center


Uncrustify

A source code beautifier for C, C++, C#, Objective-C, D, Java, Pawn and Vala.

Features

  • Highly configurable - 857 configurable options as of version 0.82.0
  • <details><summary>add/remove spaces</summary>
    • sp_before_sparen: Add or remove space before '(' of 'if', 'for', 'switch', 'while', etc.
    • sp_compare: Add or remove space around compare operator '<', '>', '==', etc
</details>
  • <details><summary>add/remove newlines</summary>
    • nl_if_brace: Add or remove newline between 'if' and '{'
    • nl_brace_while: Add or remove newline between '}' and 'while' of 'do' statement
</details>
  • <details><summary>add/remove blanklines</summary>
    • eat_blanks_before_close_brace: Whether to remove blank lines before '}'
    • nl_max: The maximum consecutive newlines (3 = 2 blank lines)
</details>
  • <details><summary>indent code</summary>
    • indent_switch_case: indent_switch_case: Spaces to indent 'case' from 'switch'
    • indent_class_colon: Whether to indent the stuff after a leading base class colon
</details>
  • <details><summary>align code</summary>
    • align_func_params: Align variable definitions in prototypes and functions
    • align_struct_init_span: The span for aligning struct initializer values (0=don't align)
</details>
  • <details><summary>modify code</summary>
    • mod_full_brace_for: Add or remove braces on single-line 'for' statement
    • mod_paren_on_return: Add or remove unnecessary paren on 'return' statement
</details>

Here is an example configuration file, and here is a before and after C source example. That should give you a pretty good idea of what Uncrustify can do.


Binaries

Pre compiled binaries for Windows can be downloaded from the Releases page or from the Sourceforge website.

Build

Python is an "interpreted high-level programming language for general-purpose programming", for this project it is needed to extend the capabilities of CMake.

CMake is a tool that generates build systems (Makefiles, Visual Studio project files, Xcode project files and others).

To generate a build system for Uncrustify using CMake on UNIX-like systems, create a build folder and run CMake from it, making sure to specify Release mode:

mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Release ..

Other systems may require other flags (e.g. cmake -G Xcode .. for Xcode).

Then use the build tools of your build system (in many cases this will simply be make, but on Windows it could be MSBuild or Visual Studio). Or use CMake to invoke it:

cmake --build . --config Release

If testing is enabled, CMake generates a test target, which you can build using your build system tools (usually make test). This can also be invoked using CTest:

ctest -V -C Debug

There is also an install target, which can be used to install the Uncrustify executable (typically make install).

A note on CMake configurations

Some build systems are single-configuration, which means you specify the build type when running CMake (by setting the CMAKE_BUILD_TYPE variable), and the generated files then build that configuration.

An example of a single-configuration build system are Makefiles. You can build the Release or Debug configurations of Uncrustify (from the build folder) with:

cmake -DCMAKE_BUILD_TYPE=Release ..
make

or

cmake -DCMAKE_BUILD_TYPE=Debug ..
make

Other build systems are multi-configuration, which means you specify the build type when building.

An example of a multi-configuration build system are Visual Studios project files. When you open the project in Visual Studio, you can select which configuration to build. You can also do this while building from the command line with cmake --build . --config Debug.

Bugs

Post any bugs to the issue tracker found on the projects GitHub page: https://github.com/uncrustify/uncrustify/issues

Please include the following with your issue:

  • a description of what is not working right
  • input code sufficient to demonstrate the issue
  • expected output code
  • configuration options used to generate the output

More about this is in the ISSUE_TEMPLATE

Known problems

Look at the Wiki

Which repositories have uncrustify?

Look here

Contribute

If you want to add a feature, fix a bug, or implement missing functionality, feel free to do so! Patches are welcome! Here are some areas that need attention:

  • Patches for Objective-C support. We really need someone who knows this language as it has more than plenty open issues. A good starting point would be to integrate changes made in the Unity fork
  • Test Java support and provide feedback (or patches!)
  • Test Embedded SQL to see what works
  • A logo of some sort
  • Anything else that you want to do to make it better?

A note about pull requests

Firstly take a look at the CONTRIBUTING.md

Currently we have two continuous integration systems that test your PRs, TravisCI and Github actions. Tested are the test cases, the formatting of the code base and the output of the command line options.

Test cases can be found in the tests/ directory. Every file ending with .test is a test set. Inside each line with these components is a single test: testNr[!] testConfigFileName testInputFileName [lang]

The configuration file testConfigFileName has to be located inside tests/config, the input file testInputFileName inside tests/input/<testSetName>/, and expected results file inside the tests/expected/<testSetName>/ directory. Expected results have the following naming convention: testNr-testInputFileName.

Optionally a ! can follow the testNr to enable a custom rerun configuration. Rerun configurations need to be named like this: testConfigFileName(without extension)+.rerun+.extension

Also, optionally a language for the input can be provided with lang.

The codebase has to be formatted by the options set up in forUncrustifySources.cfg. Failing to format the sources correctly will cause TravisCI build failures.

The Command line interface (CLI) output is tested by the test_cli_options.py script. It is located inside of tests/cli/ and operates on the subdirectories of that folder.

If a PR is altering the CLI output, files inside those directories might need to be manually updated. This often happens when options are added, removed, or altered. Keep in mind that the version string line (example: # Uncrustify-0.69.0_f) of outputs from commands like --show-config should be replaced with a blank line.

Debugging

The first method is to use uncrustify itself to get debug information. Using:

uncrustify -c myExample.cfg -f myExample.cpp -p myExample.p -L A 2>myExample.A

you get two files for the first information. The p-file gives you details of the parsing process and indentation.

# Line                Tag              Parent          Columns Br/Lvl/pp     Flag   Nl  Text
#   1>              CLASS[               NONE][  1/  1/  6/  0][0/0/0][  10070000][0-0] class
#   1>               TYPE[              CLASS][  7/  7/ 14/  1][0/0/0][  10000000][0-0]       Capteur
#   1>         BRACE_OPEN[              CLASS][ 15/ 15/ 16/  1][0/0/0][ 100000400][0-0]               {

The A-file gives you many details about the run itself, where the process is running through, which values have the most important variables.

tokenize(2351): orig line is 1, orig col is 1, text 'class', type is CLASS, orig col_end is 6
tokenize(2351): orig line is 1, orig col is 7, text 'Capteur', type is WORD, orig col_end is 14
tokenize(2351): orig line is 1, orig col is 15, text '{', type is BRACE_OPEN, orig col_end is 16

You can also dump the parsing information of each formatting step using the 'dump steps' option.

uncrustify -c myExample.cfg -f myExample.cpp -ds dump

This will create a series of 'dump_nnn.log' files, each containing the parsing information at specific points of the formatting process ('dump_000.log' will list the formatting options in use).

You can combine this option with -p and -L to get a lot of detailed debugging information.

uncrustify -c myExample.cfg -f myExample.cpp -p myExample.p -L A 2>myExample.A -ds dump

It might be useful to add some code lines to see where something is happening. Use the package unc_tools. Remove the comment at line:

#define DEVELOP_ONLY

Import the package:

#include "unc_tools.h"

Add at some places the line:

prot_the_line(__LINE__, 6, 0);

Compile again with DEBUG option.

How to add an option

If you need a new option, there are a few steps to follow. Take as example the optio

View on GitHub
GitHub Stars3.0k
CategoryDevelopment
Updated19h ago
Forks593

Languages

C++

Security Score

95/100

Audited on Apr 5, 2026

No findings