dfmt icon indicating copy to clipboard operation
dfmt copied to clipboard

Add --validate or --check

Open BlackEdder opened this issue 9 years ago • 7 comments

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.

BlackEdder avatar Jan 18 '16 10:01 BlackEdder

dfmt test.d | diff test.d -

Hackerpilot avatar Jan 18 '16 11:01 Hackerpilot

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

BlackEdder avatar Jan 18 '16 13:01 BlackEdder

You could just put a loop into a simple shell script.

Hackerpilot avatar Jan 18 '16 19:01 Hackerpilot

would you support such a PR? dfmt -diff args... returns error code 0 if nothing changed, else shows diff and returns error code 1

timotheecour avatar Feb 09 '18 01:02 timotheecour

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.

wilzbach avatar Feb 09 '18 01:02 wilzbach

Prettier has a --check options, which I usually use in the CI to ensure that properly formatted code is submitted.

aminya avatar Jun 01 '21 07:06 aminya

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.

dejlek avatar Aug 19 '22 13:08 dejlek