clang-format
automatic source code formatter for C-family languages
TLDR
Format file and output to stdout
SYNOPSIS
clang-format [options] [file...]
DESCRIPTION
clang-format is an automatic code formatting tool for C, C++, Java, JavaScript, JSON, Objective-C, Protobuf, and C# source files. It is part of the LLVM/Clang project and formats code according to configurable style rules.
The tool ships with several predefined styles (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU) and supports extensive customization through .clang-format configuration files. When using --style=file, it searches parent directories for the nearest configuration file.
clang-format integrates with most major editors and CI/CD pipelines. The --dry-run option with --Werror enables enforcement of formatting standards in automated checks without modifying files.
PARAMETERS
-i
Edit files in place--style=style
Coding style (LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, file)--dump-config
Dump configuration to stdout--assume-filename=name
Filename for language detection when reading stdin--lines=start:end
Format only specified line range--dry-run
Don't write changes, exit with error if changes needed--Werror
Treat formatting issues as errors--fallback-style=style
Style when no .clang-format found--verbose
Show files being processed
CONFIGURATION
Create .clang-format or _clang-format in project root:
IndentWidth: 4
ColumnLimit: 100
PREDEFINED STYLES
LLVM, Google, Chromium, Mozilla, WebKit, Microsoft, GNU
EDITOR INTEGRATION
Integrations available for VS Code, CLion, Vim, Emacs, Sublime Text, and most major editors.
CAVEATS
Style "file" uses nearest .clang-format in parent directories. Some formatting choices are opinionated and may require configuration adjustments.
SEE ALSO
clang(1), clang-tidy(1)
