numtide / treefmt-nix

treefmt nix configuration
https://numtide.github.io/treefmt/
MIT License
229 stars 70 forks source link

yamlfmt always updates mtime #98

Closed felschr closed 3 months ago

felschr commented 1 year ago

Describe the bug

Running yamlfmt always sets the mtime to the current date even if the contents didn't change.

To Reproduce

{
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";

    flake-parts.url = "github:hercules-ci/flake-parts";
    flake-parts.inputs.nixpkgs.follows = "nixpkgs";

    treefmt-nix.url = "github:numtide/treefmt-nix";
    treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
  };

  outputs = inputs@{ flake-parts, ... }:
    flake-parts.lib.mkFlake { inherit inputs; } {
      imports = [
        inputs.treefmt-nix.flakeModule
      ];
      systems = ["x86_64-linux"];
      perSystem = { pkgs, ... }: {
        treefmt = {
          programs.yamlfmt.enable = true;
          programs.yamlfmt.package = pkgs.yamlfmt;
        };
      };
    };
}

Add some yaml files to the workspace and observe the mtime each time treefmt --no-cache is run.

Expected behavior

treefmt-nix should not support yamlfmt since it changes mtime and thus doesn't comply with idempotence requirement of the formatter specification.

Additionally it would be nice to have a list on https://numtide.github.io/treefmt/formatters/ with known unsupported formatters and their reasons for not being supported.

System information

Inputs:
├───flake-parts: github:hercules-ci/flake-parts/8e8d955c22df93dbe24f19ea04f47a74adbdc5ec
│   └───nixpkgs-lib follows input 'nixpkgs'
├───nixpkgs: github:NixOS/nixpkgs/6cee3b5893090b0f5f0a06b4cf42ca4e60e5d222
└───treefmt-nix: github:numtide/treefmt-nix/f4ce7d8660f57fe94092cf113c1f550acf16be53
    └───nixpkgs follows input 'nixpkgs'
felschr commented 1 year ago

I guess it's worth noting that in my use case I always keep running into errors when running treefmt --no-cache --fail-on-change due to the changed mtime.

Theoretically this issue could also be fixed by treefmt ignoring timestamp changes as part of the --fail-on-change logic. Git itself doesn't track file timestamps, so it's not an issue for most people, I'd assume. Not sure if this is a good solution, but it would make treefmt compatible with a lot more formatters. E.g. I've also noticed this behaviour with buf lint & but format (they have other incompatibilities with the formatter spec, but they can easily be resolved with a wrapper script).

Related: #99

zimbatm commented 1 year ago

/cc @Ruixi-rebirth that added the formatter

terlar commented 8 months ago

Just ran into this myself. I'll see if I can open a ticket upstream if it was not done already

katexochen commented 4 months ago

Released as part of https://github.com/google/yamlfmt/releases/tag/v0.12.0

SebTM commented 3 months ago

Seems to be fixed for me and recently released 24.05-packages already include v0.12.1