Skip to content
caidoPublic

About

Shared treefmt configuration and formatter presets for Caido projects, managed with mise

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Caido formatter

This repo contains the formatting rules for every language and data serialization format that we use at caido. It contains a nix flake that provides utilities to make sure files are properly formatted in our projects. Every formatter we use is pinned here in the flake.lock and installed on the fly when the fmt command runs. It is based on treefmt-nix.

Add to any project

Add this flake.nix to your repos:

{
  inputs.caido-formatter.url = "git+ssh://git@github.com/caido/formatter";

  outputs = { self, caido-formatter, ... }:
    caido-formatter.lib.forProject self;
}

Then run:

nix fmt
nix run .#formatting-check

Add project-specific configuration

Use forProjectWith to add a treefmt-nix module to the shared configuration:

outputs = { self, caido-formatter, ... }:
  caido-formatter.lib.forProjectWith {
    source = self;
    modules = [
      {
        settings.excludes = [ "migrations/20261028180000_settings_snapshots.up.sql" ];
      }
    ];
  };

modules defaults to []. Each entry can be an attribute set, a module function, or a path to a module (for example, ./treefmt.nix). The normal Nix module merge rules apply, so settings.excludes adds project-relative patterns without replacing shared exclusions. Both nix fmt and nix run .#formatting-check use the merged configuration. Projects that don't need extra configuration can keep using forProject self.

Format SQLite files

SQL uses SQLFluff with the PostgreSQL dialect by default. To use Sqruff with the shared SQLite configuration, set sqlDialect = "sqlite"; at the top level of a project module.

outputs = { self, caido-formatter, ... }:
  caido-formatter.lib.forProjectWith {
    source = self;
    modules = [ { sqlDialect = "sqlite"; } ];
  };

Configs

treefmt.nix selects formatters and files patterns. For formatter that supports it, the config is expressed in their standard config file in config/.

configs/
  oxfmt.json
  ruff.toml
  rustfmt.toml
  stylua.toml
  sqlfluff.ini
  sqruff.ini
  ...

The language mapping is:

Files Formatter
JavaScript, TypeScript, Vue, HTML, CSS, JSON, GraphQL, Markdown, YAML Oxfmt
Python Ruff
Rust rustfmt, pinned nightly
Terraform/OpenTofu OpenTofu
Shell shfmt
Lua/Luau StyLua
Nix nixfmt
Toml taplo
SQL SQLFluff for PostgreSQL, Sqruff for SQLite

About

Shared treefmt configuration and formatter presets for Caido projects, managed with mise

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Used by

Contributors

Languages