Skip to content

settings.global.on-unmatched does not match up with treefmt behaviour #297

@PigeonF

Description

@PigeonF

Describe the bug

As far as I can tell treefmt ignores the generated global.on-unmatched setting in the generated config file.

To Reproduce

  1. Create a new treefmt-nix configuration
# flake.nix
{
  inputs.treefmt-nix.url = "github:numtide/treefmt-nix";

  outputs =
    {
      self,
      nixpkgs,
      systems,
      treefmt-nix,
    }:
    let
      # Small tool to iterate over each systems
      eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});

      # Eval the treefmt modules from ./treefmt.nix
      treefmtEval = eachSystem (
        pkgs:
        treefmt-nix.lib.evalModule pkgs {
          projectRootFile = "flake.nix";
          settings.global.on-unmatched = "debug";
        }
      );
    in
    {
      formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
    };
}
  1. Run nix fmt
$ nix fmt
2025/01/08 11:31:28 INFO using config file: /nix/store/5gvl2dmgcz24kkz81lqr3sd1bc041vjv-treefmt.toml
WARN no formatter for path: flake.nix
traversed 2 files
emitted 0 files for processing
formatted 0 files (0 changed) in 107ms
$ cat /nix/store/5gvl2dmgcz24kkz81lqr3sd1bc041vjv-treefmt.toml
[formatter]

[global]
excludes = ["*.lock", "*.patch", "package-lock.json", "go.mod", "go.sum", ".gitignore", ".gitmodules", ".hgignore", ".svnignore"]
on-unmatched = "debug"

As you can see the setting is written successfully to the config file, but treefmt does not seem to read global.on-unmatched

  1. Removing the global prefix fixes the configuration (but this does not match up with the module-options.nix)
treefmt-nix.lib.evalModule pkgs {
  projectRootFile = "flake.nix";
  # NOTE: settings.on-unmatched without the global
  settings.on-unmatched = "debug";
}
$ nix fmt
2025/01/08 11:34:35 INFO using config file: /nix/store/8zn08cfwxxb2253zg9qzvrbmbhggkbn7-treefmt.toml
traversed 2 files
emitted 0 files for processing
formatted 0 files (0 changed) in 139ms
$ cat /nix/store/8zn08cfwxxb2253zg9qzvrbmbhggkbn7-treefmt.toml
on-unmatched = "debug"
[formatter]

[global]
excludes = ["*.lock", "*.patch", "package-lock.json", "go.mod", "go.sum", ".gitignore", ".gitmodules", ".hgignore", ".svnignore"]
on-unmatched = "warn"

Expected behavior

Either treefmt should read the global.on-unmatched config setting, or treefmt-nix should change the module-options.nix to remove the global settings prefix for on-unmatched.

System information

I am using commit 13c913f5deb3a5c08bb810efd89dc8cb24dd968b, on NixOS 24.11.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions