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

typos can rename files and cause treefmt to fail with a bad error message #502

Open
jalil-salame opened this issue Dec 26, 2024 · 5 comments
Assignees
Labels
bug Something isn't working

Comments

@jalil-salame
Copy link

Describe the bug

When configured typos can cause files to be renames (e.g. hass.nix -> hash.nix). This causes treefmt to fail, but doesn't provide a good error message.

To Reproduce

Steps to reproduce the behavior:

  1. Enable the typos spell checker
  2. Create a file with a typo in the name (e.g. hass).
  3. Run treefmt and observe the following error message:
$ nix fmt -- --ci
2024/12/26 18:23:59 INFO using config file: /nix/store/my939ymfmfjl16f61pkmimzw45pbwmc1-treefmt.toml
traversed 53 files
emitted 51 files for processing
formatted 51 files (0 changed) in 1.771s
Error: failed to wait for formatters: failed to stat file: failed to stat /home/jalil/.config/nixos/machines/taurus/services/hass.nix: stat /home/jalil/.config/nixos/machines/taurus/services/hass.nix: no such file or directory
$ jj st
Working copy changes:
R machines/taurus/services/{hass.nix => hash.nix}

Expected behavior

A message should be added to explain that a file being renamed might cause the error.

System information

I use treefmt-nix which reports: treefmt v0.0.1+dev, but treefmt-2.1.0 is present in the nix-store

Additional context

This is specially weird in the nix flake check as the files in the repo are not modified but the check says the file is missing.

@jalil-salame jalil-salame added the bug Something isn't working label Dec 26, 2024
@brianmcgee brianmcgee self-assigned this Dec 31, 2024
@brianmcgee
Copy link
Member

If typos is renaming the file, you can argue that falls outside the scope of a formatter.

We can make the error more descriptive of what is happening.

It has tried to stat the file after formatting to detect changes and can no longer find it. The rename will also throw off the stats, but I don't imagine that's hugely concerning.

I invite my fellow pedants to comment @jfly @zimbatm 😄

@zimbatm
Copy link
Member

zimbatm commented Jan 4, 2025

Didn't we have another tool that was only working on the folder level? This would require changing the execution engine quite deeply.

@jfly
Copy link
Collaborator

jfly commented Jan 4, 2025

If typos is renaming the file, you can argue that falls outside the scope of a formatter.

I agree with this. I'd be OK with updating the spec accordingly.

@jalil-salame, could you invoke typos in a way where it instead only complains about filenames rather than actually renaming them?

@jalil-salame

This comment was marked as outdated.

@jalil-salame
Copy link
Author

From the reference, the only way appears to be through the typos.toml file: reference (look for defaults.check-filename)

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

4 participants