Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PigeonF opened this issue Jan 8, 2025 · 3 comments · May be fixed by #298
Open

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

PigeonF opened this issue Jan 8, 2025 · 3 comments · May be fixed by #298
Assignees
Labels
bug Something isn't working

Comments

@PigeonF
Copy link

PigeonF commented Jan 8, 2025

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.

@PigeonF PigeonF added the bug Something isn't working label Jan 8, 2025
@brianmcgee
Copy link
Member

In recent versions, the global section has been deprecated.

global.excludes is supported for backwards compatibility, but all other settings should go at the root.

https://treefmt.com/latest/getting-started/configure.

@brianmcgee brianmcgee self-assigned this Jan 8, 2025
@zimbatm
Copy link
Member

zimbatm commented Jan 8, 2025

Ok that might be solved by #268 then

@brianmcgee brianmcgee linked a pull request Jan 8, 2025 that will close this issue
@brianmcgee
Copy link
Member

I just created #298 as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants