pre-commit / pre-commit-hooks

Some out-of-the-box hooks for pre-commit
MIT License
5.2k stars 694 forks source link

`pretty-format-json` stops formatting JSONs when it encounters one with incorrect format (e.g. JSON5 comments) #1038

Closed amarvin closed 5 months ago

amarvin commented 5 months ago

Transferred from https://github.com/pre-commit/pre-commit/issues/3124.

pretty-format-json prints "Input File {json_file} is not a valid JSON, consider using check-json" when it encounters an incorrectly formatted JSON file (e.g. with JSON5 comments), but it's not clear from that message that it then stops further processing files.

As pre-commit can partition the processed files into batches, this makes it even harder to tell as multiple batches of files can fail midway through with a few "X is not a valid JSON" messages printed, giving the impression that all the JSONs were formatted (or attempted formatted) and only those files printed are incorrect. The reality is that some JSONs may not have been formatted. I think this hook should try to format every JSON and only fail at the end if any have an invalid JSON format.