dprint / dprint

Pluggable and configurable code formatting platform written in Rust.

Home Page:https://dprint.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add a flag to ignore the "No files found to format with the specified plugins" error message

bradzacher opened this issue · comments

At canva we have a CLI tool that helps us run common pre-push validation tasks (think lint-staged).
One of these tasks is obviously formatting code!

The problem we've got is that if the user touches a file that has the right extension (eg .ts), but is excluded from formatting (eg it's a generated .ts file) - dprint will fail with an error No files found to format with the specified plugins ....

This makes it cumbersome for us to integrate dprint into our tool as we either need to:

  • encode knowledge of the formattable file list into our tool, or
  • handle the failure error code then check the stderr logs for the substring, and ignore the failure in that case.

The former is doable via output-file-paths - but at our scale it's cumbersome and slow as that command for us takes around 30s to run - whereas the format of a small number of files OFC takes <10s.

I'd love it if we could have a flag like --no-error-on-ignored or something to tell dprint "I'm aware the files I'm passing might be ignored and I am okay if you ignore them".

dprint will return the 14 exit code specifically for this purpose: https://dprint.dev/cli/#exit-codes

I believe that could be used here instead of adding a flag?

That is helpful as it's more exact than a substring match of the logs - though we would still need to catch the crash, check for the exit code, and pass on the crash in all other cases.

In an ideal scenario dprint would be able to exit 0 here.

Hello, we have the same issue: if a commit doesn't contain a modification to a file included by dprint, we get the error code 14 which blocks our pre-commit hook from passing even though everything went fine.
We would like to be able to disable this behavior with a cli flag.

@cedric-spinergie it will be added soon. For now, the pre-commit hook can be modified to not fail on exit code 14

I'm thinking --allow-no-files similary to git's --allow-empty

Thank you!

One workaround I put in place is to mirror the excludes I configured in dprint.json inside my pre-commit config.
Meaning it won't even try to run dprint if there are no files for it to format.
Just telling about this in case it can help someone else in the meantime.

This is now available in 0.43.0