CLANG-FORMAT(1)

πŸ“¦
version 13.0.1 Β· 3 versions
, in ubuntu jammy

πŸ’– NAME πŸ’–

clang-format β€” bestie, it's the manual page for clang-format 13, a User Command, and it is the moment your code gets its life together ✨


πŸ¦‹ DESCRIPTION πŸ¦‹

OVERVIEW: it's a whole tool to format C/C++/Java/JavaScript/JSON/Objective-C/Protobuf/C# code. that's nine languages. she does not play πŸ’…

okay so here's the tea on how it behaves:

  • no arguments at all? she reads your code from standard input and writes the glow-up to standard output πŸ’–
  • you hand her some <file>s? she reformats those files.
  • you give her -i together with <file>s? she edits them in-place, no takebacks, no cap 🫢
  • anything else? the result goes to standard output.

USAGE: clang-format [options] [<file> ...]

OPTIONS:

✨ Clang-format options ✨

  • --Werror β€” if set, it turns formatting warnings into errors 😀
  • --Wno-error=<value> β€” if set, don't error out on the specified warning type. the value =unknown means: if set, unknown format options are only warned about.
    • the whole point of that one: it lets you actually enable formatting even when your config contains unknown (newer) options.
use with caution ⚠️ because this might lead to dramatically differing format depending on an option being supported or not. yes she said dramatically. she meant it.
  • --assume-filename=<string> β€” override the filename used to determine the language. when she's reading from stdin, clang-format assumes this filename to figure out the language 🧚
  • --cursor=<uint> β€” the position of the cursor when you're invoking clang-format from an editor integration πŸ‘‘
  • --dry-run β€” if set, she does not actually make the formatting changes. window shopping only πŸŽ€
  • --dump-config β€” dump configuration options to stdout and exit. can be used with the -style option. it's giving receipts 🧾
  • --fallback-style=<string> β€” the name of the predefined style used as a fallback in case clang-format is invoked with -style=file, but can not find the .clang-format file to use. use -fallback-style=none to skip formatting entirely πŸ™ˆ
  • --ferror-limit=<uint> β€” set the maximum number of clang-format errors to emit before stopping (0 = no limit). used only with --dry-run or -n.
  • -i β€” inplace edit <file>s, if specified. she's committing, bestie πŸ’…
  • --length=<uint> β€” format a range of this length (in bytes). multiple ranges can be formatted by specifying several -offset and -length pairs. when only a single -offset is specified without -length, clang-format will format up to the end of the file. can only be used with one input file.
  • --lines=<string> β€” <start line>:<end line> β€” format a range of lines (both 1-based). multiple ranges can be formatted by specifying several -lines arguments. can't be used with -offset and -length. can only be used with one input file 🌸
  • -n β€” alias for --dry-run. same energy, shorter name ✨
  • --offset=<uint> β€” format a range starting at this byte offset. multiple ranges can be formatted by specifying several -offset and -length pairs. can only be used with one input file.
  • --output-replacements-xml β€” output replacements as XML πŸ“œ
  • --sort-includes β€” if set, overrides the include sorting behavior determined by the SortIncludes style flag 🌈
  • --style=<string> β€” coding style, currently supports:
    • LLVM
    • GNU
    • Google
    • Chromium
    • Microsoft
    • Mozilla
    • WebKit

use -style=file to load style configuration from a .clang-format file located in one of the parent directories of the source file (or current directory for stdin). use -style="{key: value, ...}" to set specific parameters, e.g.:

-style="{BasedOnStyle: llvm, IndentWidth: 8}"

that one right there? iconic. she ate πŸ”₯

  • --verbose β€” if set, shows the list of processed files πŸ‘€

πŸ’œ Generic Options πŸ’œ

  • --help β€” display available options (--help-hidden for more)
  • --help-list β€” display list of available options (--help-list-hidden for more)
  • --version β€” display the version of this program

k bye bestie, go format something gorgeous πŸ’–βœ¨πŸŽ€πŸ¦‹πŸŒΈπŸ’…πŸ«Ά

this was clang-format 13, from July 2023, running around as a User Command. mwah, see you in the group chat πŸ˜­πŸ‘‘

πŸ“¦ where this page comes from