rtts / djhtml

Django/Jinja template indenter
GNU General Public License v3.0
582 stars 32 forks source link

Add `--check` command-line option #34

Closed craiga closed 3 years ago

craiga commented 3 years ago

Thanks so much for this tool! I've just applied it to a moderately sized Django project and it worked perfectly, cleaning up all of those inconsistently formatted templates which have been annoying me for a while now.

I'd really like is a command-line option along the lines of black's --check option, which one can use in CI to make sure their files are correctly formatted.

$ black --help
…
  --check                         Don't write the files back, just return the
                                  status. Return code 0 means nothing would
                                  change. Return code 1 means some files would
                                  be reformatted. Return code 123 means there
                                  was an internal error.
JaapJoris commented 3 years ago

Thank you @craiga, that is a great idea! I have implemented it in the latest version. If the option -c / --check is given, no file is written to disk but the exit status is equal to the number of files that would have been modified:

$ djhtml template1.html template2.html template3.html -c
3 templates would have been reindented.
$ echo $?
3

As you can see, the normal output is still there. If you want to suppress it, use -q:

$ djhtml template1.html template2.html template3.html -cq
$ echo $?
3

If you have any other suggestions you're always welcome to open an issue!