ClangFormat – automatic source code formatter

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
OCLintStatic code analysis tool for improving quality and reducing defects
cpplintStatic code checker for C++
CodeCheckerPlatform for running static analysers and managing code defects
UncrustifySource code beautifer
InferStatic analyser that detects bugs in Java, C and C++ code
Include What You UseSource analysis tool for C and C++ projects built on Clang
CppcheckStatic analysis tool for C/C++ code
flawfinderScans C and C++ source code for potential security weaknesses
clazyQt-focused static analyser that catches common C++ mistakes
ClangFormatCode formatting tool
Clang-TidyClang-based C++ “linter” tool
SmatchStatic analysis tool for finding defects in C code
CoccinelleSemantic patching tool for analysing and transforming C code

Read our verdict in the software roundup.

C# Code Formatters
UncrustifyHighly configurable source code beautifier supporting many languages
Artistic StyleFlexible source code indenter and formatter for C, C++, C# and Java
CSharpierOpinionated C# formatting with zero configuration
ClangFormatAutomatically formats C, C++, Java and other source code consistently

Read our verdict in the software roundup.


Best Free and Open Source Software 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.
Subscribe

Please read our Comment Policy before commenting.

Notify of
guest
0 Comments
Oldest
Newest Most Voted