ClangFormat is a source code formatting tool developed as part of the LLVM project. It helps maintain consistent coding styles across projects by automatically adjusting indentation, whitespace, line breaks and other aspects of source code layout.
The software supports C and C++ alongside several other programming languages. Developers can choose from predefined formatting styles or create their own conventions using configuration files stored with their source code.
ClangFormat can operate as a standalone command-line utility or integrate with text editors and development environments. It also supports formatting selected portions of a file, making it useful for applying consistent styles without reformatting an entire codebase.
This is free and open source software.
Key Features
- Automatic source code formatting for C, C++ and Objective-C.
- Additional language support including Java, JavaScript, JSON, C#, Protocol Buffers and other supported formats.
- Predefined formatting styles including LLVM, GNU, Google, Chromium, Microsoft, Mozilla and WebKit.
- Custom styles defined through .clang-format or _clang-format configuration files.
- Control over indentation, whitespace, line breaks and brace placement.
- Configure pointer alignment, column limits and numerous other formatting rules.
- Automatic sorting of include directives according to the selected style.
- Format selected lines or byte ranges rather than entire files.
- Modify files in place or write formatted output to standard output.
- Dry-run mode for checking formatting without changing source files.
- Report formatting violations as errors for use in automated checks.
- Generate configuration files from predefined styles.
- Support for editor and IDE integrations.
- Integration with Git-based workflows for formatting changed code.
Website: clang.llvm.org
Support:
Developer: LLVM Project
License: Apache License 2.0 with LLVM Exceptions
ClangFormat is written in C++. Learn C++ with our recommended free books and free tutorials.
Related Software
| C and C++ Linters | |
|---|---|
| OCLint | Static code analysis tool for improving quality and reducing defects |
| cpplint | Static code checker for C++ |
| CodeChecker | Platform for running static analysers and managing code defects |
| Uncrustify | Source code beautifer |
| Infer | Static analyser that detects bugs in Java, C and C++ code |
| Include What You Use | Source analysis tool for C and C++ projects built on Clang |
| Cppcheck | Static analysis tool for C/C++ code |
| flawfinder | Scans C and C++ source code for potential security weaknesses |
| clazy | Qt-focused static analyser that catches common C++ mistakes |
| ClangFormat | Code formatting tool |
| Clang-Tidy | Clang-based C++ “linter” tool |
| Smatch | Static analysis tool for finding defects in C code |
| Coccinelle | Semantic patching tool for analysing and transforming C code |
Read our verdict in the software roundup.
| C# Code Formatters | |
|---|---|
| Uncrustify | Highly configurable source code beautifier supporting many languages |
| Artistic Style | Flexible source code indenter and formatter for C, C++, C# and Java |
| CSharpier | Opinionated C# formatting with zero configuration |
| ClangFormat | Automatically formats C, C++, Java and other source code consistently |
Read our verdict in the software roundup.
Explore our carefully curated directory of recommended free and open source software, covering every major software category.The directory forms part of our extensive collection of articles for Linux enthusiasts. It includes hundreds of detailed reviews, together with free and open source alternatives to proprietary software from companies such as Google, Microsoft, Apple, Adobe, IBM, Cisco, Oracle, and Autodesk. LinuxLinks also covers interesting projects worth exploring, Linux-compatible hardware, free programming books and tutorials, and much more. Know a useful free and open source Linux application that we haven’t covered? Tell us about it using our submission form. |


Please read our Comment Policy before commenting.