dfmt
dfmt copied to clipboard
Add --validate or --check
Would be nice to have an option which checks whether formatting is correct and errors when it is not. That would make it easy to add as a pre-commit git hook.
dfmt test.d | diff test.d -
That doesn't work for when you pass it multiple files though (find -name "*.d" | xargs dfmt), probably because that seems to automatically turn on the in place flag
You could just put a loop into a simple shell script.
would you support such a PR?
dfmt -diff args...
returns error code 0 if nothing changed, else shows diff and returns error code 1
Yes. Motivation: if we want to use this for e.g. Phobos or DMD, someone might be running Windows ...
I know that the DMD testsuite requires diff
, but Phobos doesn't and it's also an interesting option for other projects who want to slowly convert their code to one style.
Prettier has a --check
options, which I usually use in the CI to ensure that properly formatted code is submitted.
I humbly believe both --check
and --diff
would be good additions. --check
can actually be in the same implementation as --diff
- it would just not output anything. In most cases I really do not care about diff, I just want to refuse PR if it is not formatted according to the coding standard adopted by the company. Also suitable for pre-commit hook.