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

In Git repository, only first file is formatted when passing multiple file paths #253

Open
evolutics opened this issue Oct 27, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@evolutics
Copy link

Thanks for your work on treefmt.

Describe the bug

When running treefmt-nix with a list of files to format, only the first file is considered while any remaining files are ignored. This only happens in a Git repository.

It works when passing --walk filesystem as an option.

To Reproduce

Steps to reproduce the behavior:

  1. Ensure you are in a Git repository.

  2. Set up treefmt-nix with these (intentionally unformatted) files:

    • flake.nix with a default app to run the treefmt-nix wrapper:

      {
        inputs.treefmt-nix.url = "github:numtide/treefmt-nix";
      
        outputs = {
          self,
          nixpkgs,
          systems,
          treefmt-nix
        }: let
          eachSystem = f: nixpkgs.lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system});
          treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix);
        in {
          formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper);
      
          apps = eachSystem (pkgs: {
            default = {
              program = "${treefmtEval.${pkgs.system}.config.build.wrapper}/bin/treefmt";
              type = "app";
            };
          });
        };
      }
    • treefmt.nix:

      {pkgs, ...}:
      {
        projectRootFile = "flake.nix";
        programs.alejandra.enable = true;
      }
  3. Run treefmt-nix against the Nix files with

    $ git add .
    
    $ nix run . -- flake.nix treefmt.nix
    
    traversed 1 files
    emitted 1 files for processing
    formatted 1 files (1 changed) in 11ms

Now only flake.nix is formatted but treefmt.nix is ignored.

Expected behavior

Both files should be formatted.

System information

Ubuntu 24.04.1 LTS with Nix 2.24.9.

flake.lock:

{
  "nodes": {
    "nixpkgs": {
      "locked": {
        "lastModified": 1729980323,
        "narHash": "sha256-eWPRZAlhf446bKSmzw6x7RWEE4IuZgAp8NW3eXZwRAY=",
        "owner": "NixOS",
        "repo": "nixpkgs",
        "rev": "86e78d3d2084ff87688da662cf78c2af085d8e73",
        "type": "github"
      },
      "original": {
        "id": "nixpkgs",
        "type": "indirect"
      }
    },
    "nixpkgs_2": {
      "locked": {
        "lastModified": 1726871744,
        "narHash": "sha256-V5LpfdHyQkUF7RfOaDPrZDP+oqz88lTJrMT1+stXNwo=",
        "owner": "nixos",
        "repo": "nixpkgs",
        "rev": "a1d92660c6b3b7c26fb883500a80ea9d33321be2",
        "type": "github"
      },
      "original": {
        "owner": "nixos",
        "ref": "nixpkgs-unstable",
        "repo": "nixpkgs",
        "type": "github"
      }
    },
    "root": {
      "inputs": {
        "nixpkgs": "nixpkgs",
        "systems": "systems",
        "treefmt-nix": "treefmt-nix"
      }
    },
    "systems": {
      "locked": {
        "lastModified": 1681028828,
        "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
        "owner": "nix-systems",
        "repo": "default",
        "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
        "type": "github"
      },
      "original": {
        "id": "systems",
        "type": "indirect"
      }
    },
    "treefmt-nix": {
      "inputs": {
        "nixpkgs": "nixpkgs_2"
      },
      "locked": {
        "lastModified": 1729613947,
        "narHash": "sha256-XGOvuIPW1XRfPgHtGYXd5MAmJzZtOuwlfKDgxX5KT3s=",
        "owner": "numtide",
        "repo": "treefmt-nix",
        "rev": "aac86347fb5063960eccb19493e0cadcdb4205ca",
        "type": "github"
      },
      "original": {
        "owner": "numtide",
        "repo": "treefmt-nix",
        "type": "github"
      }
    }
  },
  "root": "root",
  "version": 7
}

Additional context

As a workaround, run

nix run . -- --walk filesystem flake.nix treefmt.nix
@evolutics evolutics added the bug Something isn't working label Oct 27, 2024
@brianmcgee
Copy link
Member

Path handling has been improved recently on main numtide/treefmt#438

I am hoping to get a release cut in the next week or so.

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

No branches or pull requests

2 participants