nufmt icon indicating copy to clipboard operation
nufmt copied to clipboard

Won't format files that don't end in `.nu`

Open dannyfritz opened this issue 1 month ago • 5 comments

Describe the bug

I have a shell command written in nu that has a shebang at the top. I cannot get nufmt to format this file unless I rename it to *.nu or I use the --stdin flag.

https://github.com/nushell/nufmt/blob/35962223fbd4c1a924b4ccfb8c7ad81fe2863b86/src/main.rs#L319-L322

Steps To Reproduce

Steps to reproduce the behavior:

  1. Have nu file without the .nu file extension such as my-command
  2. Run nufmt my-command
  3. Observe error "warning: no Nushell files found under the given path(s)⏎"

Expected behavior

I expect nufmt to format the file because I specified the file on the CLI.

Environment

Please run rustc --version and paste the result.

[user@system:~]$ rustc --version
rustc 1.91.1 (ed61e7d7e 2025-11-07)

dannyfritz avatar Nov 16 '25 03:11 dannyfritz

I'm not surprised. nufmt isn't even beta yet and I wouldn't suggest using it. However, we are able to take PRs to help fix problem. I myself use topiary-nushell right now.

fdncred avatar Nov 16 '25 12:11 fdncred

I'm not surprised. nufmt isn't even beta yet and I wouldn't suggest using it. However, we are able to take PRs to help fix problem. I myself use topiary-nushell right now.

Thanks. That looks like a really interesting project.

  • https://github.com/blindFS/topiary-nushell
  • https://github.com/tweag/topiary

dannyfritz avatar Nov 16 '25 13:11 dannyfritz

Hey! For completeness, if you format a directory with nufmt, should nufmt check if the shebang of everyfile to see if it needs formatting or not? This would significantly hit performance if you need to read thousands of files just to format a couple of them

AucaCoyan avatar Nov 17 '25 14:11 AucaCoyan

Hey! For completeness, if you format a directory with nufmt, should nufmt check if the shebang of everyfile to see if it needs formatting or not? This would significantly hit performance if you need to read thousands of files just to format a couple of them

The feature could be designed to be disabled with a flag if there is a performance hit for edge cases.

dannyfritz avatar Nov 17 '25 20:11 dannyfritz

Maybe a link to topiary-nushell could be included in the readme warning?

siph avatar Nov 18 '25 23:11 siph