Uncrustify is a tool that can automatically format your source code according to a set of rules that you can customize. It can handle various aspects of code formatting, such as indentation, spacing, alignment, and braces. It can also sort your includes, align your comments, and add or remove newlines.
By using Uncrustify, you can benefit from the following advantages:
- It can save time and effort by letting Uncrustify do the formatting for you.
- You can ensure that your code follows a consistent style across different files and projects.
- It can improve the readability and maintainability of your code, which can help you find and fix bugs faster.
- You can avoid conflicts and merge issues that may arise from different formatting preferences.
To install Uncrustify on Ubuntu execute
install_dependencies.shscript. Configuration fileuncrustify.cfgwill be present at cerberus-core repo path:~/<repo_location>/cerberus/uncrustify.cfg
Executable will be generated inside build directory.
~/build_tools/uncrustify/build/uncrustifyCopy the executable to /usr/bin folder.~/build_tools/uncrustify/build$ sudo cp uncrustify /usr/binVerify with below command (execute from any path).uncrustify -v
Install Extension: Uncrustify by Zachary Flower
Uncrustify either set up the format on save feature in Visual Studio Code.
Alternatively, format the file manually by right-clicking and selecting the option to format the document (Right Click -> Format Document).
If you require to run
uncrustify_foramt.shscript manually then follow below instructions,
-
Set build tools and directory path:
BUILD_TOOLS: Set the directory path for build_tools.BUILD_STAGINGDIRECTORY: Set repo directory path.
-
Modify the script variables in
uncrustify_format.sh:UNC_DIR: Set the directory path for Uncrustify.UNC_EXECUTABLE: Set the path to the Uncrustify executable.UNC_CNF_FILE: Set the path to your Uncrustify configuration file (uncrustify.cfg).UNC_CHK_SRC_FILES: Set the path to the source code files which would be passed to script to check and format.
-
Run the script:
bash uncrustify_format.sh
-
Source code formatted changes can be seen by
git diffon repo. -
Re-execute
uncrustify_format.shafter file update to verify no more formatting error exists.