fx format-code

runs source formatters on modified files

Usage: fx format-code
          [--dry-run] [--verbose] [--all]
          [--files=FILES,[FILES ...]]
          [--target=GN_TARGET]
          [--git] [--changed-lines] [-- PATTERN]

  --dry-run Stops the program short of running the formatters
  --all     Formats all code in the git repo under the current working
            directory.
  --args    Formats the configured build's |args.gn|
  --files   Allows the user to specify files.  Files are comma separated.
            Globs are dealt with by bash; fx format-code "--files=foo/*" will
            work as expected.
  --target  Allows the user to specify a gn target. If the template for the
            given target is defined in a .gni file, the files to format may
            be forwarded to another target, and specifying the target may not
            work.  The workaround is to pass the target to which the files
            are forwarded, instead.  Specifically, as of January 2023, you
            can only use this with rustc binary and library targets by
            appending ".actual" to them.
  --git     The default; it uses `git diff` against the newest parent
            commit in the upstream branch (or against HEAD if no such commit
            is found).  Files that are locally modified, staged or touched by
            any commits introduced on the local branch are formatted.
  --changed-lines
            Format changed lines only. Only supported on a subset of languages
            (currently, just C++). Unsupported languages will continue to have
            the entire file formatted. "Changes" are relative to the git
            commit that would be used by "--git".
  --parallel
            Formats all files in the background rather than waiting on each one
            before starting the next.
            WARNING: with this flag enabled, output from multiple formatters
            may be interleaved, and format-code will exit with status 0 even
            if some formatters failed.
  --verbose Print all formatting commands prior to execution.
   -- PATTERN
            For --all or --git, passes along -- PATTERN to `git ls-files`
            to filter what files are affected. For example, to format all
            rust source files use `fx format-code --all -- "*.rs"`

Supported Languages: C, C++, cml, Dart, FIDL, GN, Go, Python, Rust, JSON

format-code source code