CLANG-FORMAT(1)

πŸ“¦ version 12.0.1, in ubuntu jammy

πŸ’– clang-format β€” the manual page, bestie edition πŸ’–

okay so this is the manual page for clang-format, from section 1 (User Commands). yes, that clang-format. the one your editor keeps yelling at you to configure. let's get into it ✨


🌸 DESCRIPTION 🌸

OVERVIEW: it's a tool that formats C/C++/Java/JavaScript/Objective-C/Protobuf/C# code. that's the whole gig. it takes your chaotic little code gremlin and makes it presentable. πŸ’…

so here's how it behaves, and this part matters:

  • no arguments at all? it reads code from standard input and writes the result to standard output.
  • you pass <file>s? it reformats those files.
  • you pass -i together with <file>s? it edits the files in-place. no takebacks.
  • otherwise? the result goes to standard output.

USAGE:

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

✨ OPTIONS ✨

πŸŽ€ Clang-format options

  • --Werror β€” if you set this, formatting warnings get promoted to full-on errors. no more gentle vibes, we're being serious now.
  • --Wno-error=<value> β€” if you set this, it won't error out on the warning type you named.
    • =unknown β€” if you set this one, unknown format options are only warned about instead of being a whole thing.
this is what you use to keep formatting going even when your config has unknown (newer) options in it. use with caution tho β€” because depending on whether an option is supported or not, your format could come out dramatically different. 😭
  • --assume-filename=<string> β€” overrides the filename that gets used to figure out the language. when it's reading from stdin, clang-format assumes this filename to determine the language. iykyk.
  • --cursor=<uint> β€” the position of the cursor when you invoke clang-format from an editor integration. (hi, editor plugins πŸ‘‹)
  • --dry-run β€” if set, it does not actually make the formatting changes. all vibes, no edits.
  • --dump-config β€” dumps the configuration options to stdout and then exits. can be used together with the -style option.
  • --fallback-style=<string> β€” the name of the predefined style used as a fallback when clang-format is invoked with -style=file but can't find the .clang-format file to use. use -fallback-style=none to skip formatting entirely.
  • --ferror-limit=<uint> β€” sets the max number of clang-format errors to emit before stopping (0 = no limit). only used with --dry-run or -n.
  • -i β€” inplace-edit the <file>s, if specified. ✏️
  • --length=<uint> β€” format a range of this length (in bytes). you can format multiple ranges by specifying several -offset and -length pairs. when only a single -offset is given without -length, clang-format formats 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, bestie, don't forget). multiple ranges = 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 again = several -offset and -length pairs. can only be used with one input file.
  • --output-replacements-xml β€” outputs the replacements as XML.
  • --sort-includes β€” if set, this overrides the include sorting behavior that the SortIncludes style flag would have decided. it's giving main character energy, honestly.
  • --style=<string> β€” the coding style. currently supported: LLVM, GNU, Google, Chromium, Microsoft, Mozilla, WebKit.

use -style=file to load the style config from a .clang-format file sitting in one of the parent directories of the source file (or the current directory, if you're on stdin). use -style="{key: value, ...}" to set specific parameters, like:

-style="{BasedOnStyle: llvm, IndentWidth: 8}"
  • --verbose β€” if set, it shows you the list of processed files. so you can see exactly what it touched. πŸ‘€

🌈 Generic Options

  • --help β€” display the available options (there's --help-hidden for more, if you're nosy).
  • --help-list β€” display the list of available options (and --help-list-hidden for more).
  • --version β€” display the version of this program.

and that's the whole page, bestie. every flag, every default, every warning, preserved exactly β€” just with way better vibes. go forth and format. πŸ¦‹

this was clang-format version 12, from February 2022, section 1 of the manual. slay. periodt. πŸ’–

πŸ“¦ where this page comes from