README.md

May 1, 2026 ยท View on GitHub

logo banner

A customizable code formatter for the C3 language, written in C3.

Usage

Usage:

c3fmt [<options>] <files/directories>

Options:

-h, --help       - Show this help.
-v, --version    - Show current version.
--in-place       - Format files in place.
--stdin          - Read input from stdin.
--stdout         - Output result to stdout.
--config=<path>  - Specify a config file.
--default        - Force default config.
--check          - Finish with error if files are not formatted.

Configuration

c3fmt will try to find a .c3fmt configuration file inside the working directory. You can also pass your own path to c3fmt using the --config flag, or force the default configuration with --default.

You can look at .c3fmt for the default configuration.

Available Options

KeyDescriptionDefault
use_tabsUse tabs for indentation.true
tab_sizeThe width of a tab character.4
indent_widthThe number of spaces to use for indentation (if use_tabs is false).4
max_blank_line_between_statementsMaximum number of blank lines to preserve between statements.2
max_line_lengthMaximum line length before wrapping.120
brace_styleThe brace style to use: ALLMAN or K&R.ALLMAN
else_on_newlineWhether to put else on a new line.true
align_assignmentsAlign = and => in consecutive declarations/assignments.true
align_commentsAlign trailing comments in consecutive lines.true

Building

Building requires the C3 compiler and the tree-sitter SDK library. For instructions on how to build and install the tree-sitter library, refer to the tree-sitter getting started guide.

To build the executable:

c3c build

If the tree-sitter library is not in your system's default search path, you can specify the path using the -L flag:

c3c build -L /path/to/tree-sitter/lib

The binary will be located in build/c3fmt.

Updating Sources

You can keep the project dependencies and test data up-to-date using the built-in prepare targets:

  • Tree-sitter Grammar: Update the C3 grammar parser from upstream.
    c3c build update-grammar --trust=full
    
  • Standard Library: Sync test/stdlib/src with the latest C3 standard library for stability testing.
    c3c build update-stdlib --trust=full
    

Tests

Run all tests using the C3 compiler:

c3c test

Just like with the build command, if tree-sitter is not in your search path, use the -L flag:

c3c test -L /path/to/tree-sitter/lib

The test suite includes:

  • Corpus: Compares formatted output against expected _f.c3 files.
  • Stability: Ensures that formatting already-formatted code produces no changes (idempotency).
  • Stdlib: Formats the entire C3 standard library and verifies that it still compiles and maintains the same syntax tree.

Vendored libraries

  • src/opt.c3: A vendored copy of getopt.c3l.
  • lib/tree_sitter.c3l: C3 bindings for the core tree-sitter SDK.
  • lib/tree_sitter_c3.c3l: C3 grammar bindings for tree-sitter.

Planned features / wishlist

  • Wrapping indent option (ContinuationIndentWidth).
  • Import sorting.
  • Pointer alignment calibration.

Known issues

(none yet)