LLMpediaThe first transparent, open encyclopedia generated by LLMs

clang-format

Generated by GPT-5-mini
Note: This article was automatically generated by a large language model (LLM) from purely parametric knowledge (no retrieval). It may contain inaccuracies or hallucinations. This encyclopedia is part of a research project currently under review.
Article Genealogy
Parent: Clang Hop 5
Expansion Funnel Raw 62 → Dedup 0 → NER 0 → Enqueued 0
1. Extracted62
2. After dedup0 (None)
3. After NER0 ()
4. Enqueued0 ()
clang-format
Nameclang-format
DeveloperLLVM Project
Released2012
Programming languageC++
Operating systemLinux, macOS, Microsoft Windows
GenreSoftware development
LicenseUniversity of Illinois/NCSA Open Source License

clang-format is a source code formatter from the LLVM Project designed to enforce consistent coding style for C++, C, Objective-C, Java, JavaScript, TypeScript, Protocol Buffers, and other languages. It is distributed with the Clang (compiler) front end and is part of the LLVM toolchain; it automates indentation, line breaking, and spacing rules to match project style guides such as those used at Google (company), Mozilla, and Chromium (project). The tool is widely used in continuous integration pipelines for projects hosted on platforms like GitHub, GitLab, and Bitbucket.

Overview

clang-format is built atop the Clang (compiler) parser and the LLVM infrastructure to perform syntax-aware formatting, distinguishing it from simple text-based reformatters like sed or awk. It supports style profiles inspired by industry standards including Google (company), LLVM, Chromium (project), Mozilla, and Microsoft conventions, enabling consistent output across heterogeneous codebases developed at organizations such as Facebook, Apple Inc., and Netflix. The project is maintained through the LLVM Project governance and contributions from developers affiliated with companies like Google (company), Apple Inc., NVIDIA, and independent contributors from communities such as LLVM Developers Group.

Features and Configuration

clang-format offers features including AST-aware reflowing of comments, alignment of parameters, column limit enforcement, and reformatting of macros in C preprocessor contexts. Configuration is driven by a YAML-style .clang-format file or command-line flags; common keys map to style rules like IndentWidth, ColumnLimit, and BraceWrapping used by teams at Google (company), Chromium (project), and Mozilla. It supports options for controlling pointer alignment, sorting of includes (via integrations), and formatting of template declarations used in projects at Intel, AMD, and ARM. The tool can operate in place, produce diffs, or run as part of formatter services embedded in editors such as Visual Studio Code, CLion, Vim, and Emacs.

Supported Languages and Style Options

clang-format recognizes language grammars derived from the Clang (compiler) front end and thus formats C++, C, Objective-C, Objective-C++, Java, JavaScript, TypeScript, ProtoBufs (protocol buffers), and selected YAML-like constructs. Style presets include canonical profiles named after organizations like Google (company), LLVM, Chromium (project), Mozilla, and Microsoft; each preset encapsulates conventions for indentation, wrapping, and spacing used in large codebases at those organizations. Additional fine-grained options permit control over AlignConsecutiveAssignments, AllowShortIfStatementsOnASingleLine, and BinPackParameters — settings similar to coding rules adopted in projects at Intel, NVIDIA, Facebook, and Apple Inc..

Integration and Tooling

clang-format integrates with source control workflows common to Git and hosting services such as GitHub, GitLab, and Bitbucket Server. It is commonly invoked in pre-commit hooks using frameworks like pre-commit and Husky or within continuous integration systems like Jenkins, Travis CI, CircleCI, and Azure Pipelines. Editor plugins exist for Visual Studio Code, Sublime Text, CLion, Xcode, Eclipse, Vim, and Emacs, enabling on-save formatting consistent with repository rules. Enterprise adoption is facilitated via integrations with code review tools such as Gerrit and Phabricator, and with build systems including CMake, Bazel, and Make (software).

Usage Examples and Common Patterns

Common usage patterns include formatting a single file with command-line flags, applying a repository-wide style with a committed .clang-format file, and using clang-format in staged pre-commit workflows to avoid noisy diffs in GitHub pull requests. Typical commands are executed in shells on Linux, macOS, or Microsoft Windows hosts and are often wrapped by scripts in languages like Bash (Unix shell), Python (programming language), or PowerShell to format changed files detected by tools such as git-clang-format or diff. Teams at Google (company), Chromium (project), and Mozilla adopt patterns that include CI gating, automated reformatting bots, and clear style documentation in README files to reduce review overhead during contributions from developers using IDEs like Visual Studio Code or CLion.

Development, Licensing, and History

clang-format originated as part of the Clang (compiler) project within the LLVM umbrella, with early contributions from engineers at Google (company) and Apple Inc. during the 2010s. Its development is coordinated via the LLVM Project repositories and discussions on mailing lists and issue trackers used by contributors from organizations including Google (company), Apple Inc., Intel, NVIDIA, and independent open-source maintainers. The code is released under the University of Illinois/NCSA Open Source License, permitting permissive reuse in commercial and open-source projects, and it has evolved to add language support, style options, and editor integrations driven by demand from large codebases at Mozilla, Chromium (project), and Facebook. Ongoing maintenance aligns with LLVM release cycles and contributions managed through Phabricator and modern migration to platforms like GitHub.

Category:Software