"No files found to format with the specified plugins at [...]" unless project is git repository (confused me)
Hi, I am not sure if this is a bug or expected behavior. I only got dprint to run in a git folder/project.
I set up a new project without initializing git from the start and I just could not get dprint to format anything. I only got the No files found to format [...] message. Neither with (pnpx) dprint fmt or by specifying a file (pnpx) dprint fmt "dprint.json". Only after I ran git init it was possible to format something.
My expectation was, that dprint would use the cwd or the closest directory with a dprint.json from the cwd or something like that. In contrast prettier dprint.json --write works for me.
If this is expected behavior, I think it should be mentioned in the documentation. As far as I can tell (I hope I didn't miss anything), this is not explicitly stated. I wouldn't mind creating a PR for that.
dprint version is 0.47.2
What does your dprint.json look like? It works fine for me even not in a git repository.
{
"json": {
"indentWidth": 2
},
"excludes": [
"**/node_modules",
"**/*-lock.json"
],
"plugins": [
"https://plugins.dprint.dev/json-0.19.3.wasm"
]
}
Just a very simple test project.
Oh no, I was afraid it could be a problem on my side.
macOS 14.5
zsh
dprint via homebrew, but was also using pnpmx dprint ...
I manage some ~/ config files via git, so my home directory is a git repo. Wonder if that could have an influence? (Though I already tested to rename ~/.git to something else, same result)
I manage some ~/ config files via git, so my home directory is a git repo. Wonder if that could have an influence? (Though I already tested to rename ~/.git to something else, same result)
It might be. It discovers .gitignore files for example. Is there a gitignore file? The code for doing .gitignore is here: https://github.com/dprint/dprint/blob/86a20b65625485c29273e5da986126cd9c678ebd/crates/dprint/src/utils/gitignore.rs#L87
The dprint config you provided works fine for me outside a git repo. Maybe running with debug logging might give more insights (pnpx dprint fmt --log-level=debug)
Oh gosh, of course!
I was so close ... I gitignore everything * in ~/.gitignore to track just a few specific files. And that .gitignore was taken into account by dprint. So:
- dprint formats the files when I disable the whole home git thing.
- also, dprint formats the files when the whole home git thing is active, and an empty gitignore is added to the project folder.
Thank you!
Apart from my problem being quite the edge case, I wonder if it would be helpful if --verbose/--log-level=debug should also print the gitignore patterns (and their origin) which were taken into account.
Also from the verbose output:
[DEBUG] Reading file: /Users/__/.gitignore ← actual home .gitignore
[DEBUG] Reading file: /Users/__/__/.gitignore ← does not exist
[DEBUG] Reading file: /Users/__/__/__/.gitignore ← does not exist
[DEBUG] Reading file: /Users/__/__/__/__/.gitignore ← does not exist
[DEBUG] Reading file: /Users/__/__/__/__/__/.gitignore ← actual project .gitignore
The "Reading file" might be misleading here, as most .gitignore files actually don't exist. Maybe a "Checking file" here with a following "using file" could clarify some what is actually happening.
Just some ideas, wonder what you think.
Please use:
git config --local status.showUntrackedFiles no
Instead of:
I gitignore everything
*in~/.gitignoreto track just a few specific files.
This is a very nefarious footgun.