Skip to main content

Formatters

CoStrict automatically formats files after writing or editing them, keeping generated code consistent with your project's style.


Built-in Formatters

CoStrict includes formatters for most popular languages. A formatter activates automatically when its requirements are met:

FormatterSupported ExtensionsRequirement
prettier.js .jsx .ts .tsx .html .css .md .json .yaml and moreprettier in package.json
biome.js .jsx .ts .tsx .html .css .md .json .yaml and morebiome.json(c) config file present
gofmt.gogofmt command available
rustfmt.rsrustfmt command available
cargofmt.rscargo fmt command available
ruff.py .pyiruff command available with config
uv.py .pyiuv command available
shfmt.sh .bashshfmt command available
clang-format.c .cpp .h .hpp .ino and more.clang-format config file present
dart.dartdart command available
ktlint.kt .ktsktlint command available
terraform.tf .tfvarsterraform command available
zig.zig .zonzig command available
rubocop.rb .rake .gemspec .rurubocop command available
standardrb.rb .rake .gemspec .rustandardrb command available
pint.phplaravel/pint in composer.json
mix.ex .exs .eex .heex and moremix command available
ocamlformat.ml .mliocamlformat available with config file
ormolu.hsormolu command available
cljfmt.clj .cljs .cljc .edncljfmt command available
gleam.gleamgleam command available
nixfmt.nixnixfmt command available
dfmt.ddfmt command available
air.Rair command available
htmlbeautifier.erb .html.erbhtmlbeautifier command available

For example, if your project's package.json includes prettier, CoStrict will automatically use it for formatting.


How It Works

When CoStrict writes or edits a file, it:

  1. Matches the file extension against all enabled formatters
  2. Runs the matching format command
  3. Applies the result automatically

The entire process runs in the background — no manual steps required.


Configuration

Customize formatters via the formatter option in costrict.json:

costrict.json
{
"$schema": "https://opencode.ai/config.json",
"formatter": {}
}

Each formatter entry supports:

PropertyTypeDescription
disabledbooleanSet to true to disable this formatter
commandstring[]Command to run ($FILE is replaced with the file path)
environmentobjectEnvironment variables to set when running the formatter
extensionsstring[]File extensions this formatter handles

Disable All Formatters

costrict.json
{
"$schema": "https://opencode.ai/config.json",
"formatter": false
}

Disable a Specific Formatter

costrict.json
{
"$schema": "https://opencode.ai/config.json",
"formatter": {
"prettier": {
"disabled": true
}
}
}

Custom Formatter

Override a built-in formatter or add a new one:

costrict.json
{
"$schema": "https://opencode.ai/config.json",
"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 is replaced with the actual file path.