Skip to content

Formatters

Anthracode uses language specific formatters.

Anthracode can format files after they are written or edited using language-specific formatters. Formatters are disabled by default; enable them in your config before Anthracode will run them.


Anthracode comes with several built-in formatters for popular languages and frameworks. Below is a list of the formatters, supported file extensions, and commands or config options it needs.

FormatterExtensionsRequirements
air.Rair command available
biome.js, .jsx, .ts, .tsx, .html, .css, .md, .mdx, .json, .yaml, .toml, .xml, .graphql, and morebiome.json(c) config file
rustfmt.rsrustfmt command available
clang-format.c, .cc, .cpp, .h, .hh, .hpp, .ino, and more.clang-format config file
cljfmt.clj, .cljs, .cljc, .edncljfmt command available
dart.dartdart command available
dfmt.ddfmt command available
gleam.gleamgleam command available
gofmt.gogofmt command available
htmlbeautifier.erb, .html.erbhtmlbeautifier command available
ktlint.kt, .ktsktlint command available
latexindent.texlatexindent command available
mix.ex, .exs, .eex, .heex, .leex, .neex, .sfacemix command available
nixfmt.nixnixfmt command available
ocamlformat.ml, .mliocamlformat command available and .ocamlformat config file
ormolu.hsormolu command available
oxfmt (Experimental).js, .jsx, .mjs, .cjs, .ts, .tsx, .mts, .ctsoxfmt dependency in package.json and an experimental env variable flag
pint.phplaravel/pint dependency in composer.json
prettier.js, .jsx, .ts, .tsx, .html, .css, .md, .mdx, .json, .yaml, .toml, .xml, .graphql, and moreprettier dependency in package.json
rubocop.rb, .rake, .gemspec, .rurubocop command available
ruff.py, .pyiruff command available with config
shfmt.sh, .bashshfmt command available
standardrb.rb, .rake, .gemspec, .rustandardrb command available
terraform.tf, .tfvarsterraform command available
uv.py, .pyiuv command available
zig.zig, .zonzig command available

When formatters are enabled, Anthracode will use prettier for matching files if your project has prettier in package.json.


When Anthracode writes or edits a file and formatters are enabled, it:

  1. Checks the file extension against all enabled formatters.
  2. Runs the appropriate formatter command on the file.
  3. Applies the formatting changes.

This process happens in the background for enabled formatters.


You can enable and customize formatters through the formatter section in your Anthracode config.

To enable all built-in formatters, set formatter to true.

anthracode.jsonc
{
"formatter": true
}

Use an object to keep built-ins enabled while configuring overrides or custom formatters.

anthracode.jsonc
{
"formatter": {}
}

Each formatter configuration supports the following:

PropertyTypeDescription
disabledbooleanSet this to true to disable the formatter
commandstring[]The command to run for formatting. Required for custom formatters; optional for built-ins.
environmentobjectEnvironment variables to set when running the formatter
extensionsstring[]File extensions this formatter should handle

Let’s look at some examples.


If formatter is omitted, all formatters are disabled. To disable all formatters after another config enabled them, set formatter to false:

anthracode.jsonc
{
"formatter": false
}

To disable a specific formatter, set disabled to true:

anthracode.jsonc
{
"formatter": {
"prettier": {
"disabled": true
}
}
}

You can configure built-in formatters with options like environment or extensions. To add a custom formatter, specify a command and extensions:

anthracode.jsonc
{
"formatter": {
"prettier": {
"command": ["npx", "prettier", "--write", "$FILE"],
"environment": {
"NODE_ENV": "development"
},
"extensions": [".js", ".ts", ".jsx", ".tsx"]
},
"custom-markdown-formatter": {
"command": ["deno", "fmt", "$FILE"],
"extensions": [".md"]
}
}
}

The $FILE placeholder in the command will be replaced with the path to the file being formatted.