zaach / jsonlint

A JSON parser and validator with a CLI.
http://zaach.github.com/jsonlint/
1.93k stars 417 forks source link

--sort-keys doesn't exits with exit code 0 even if keys were not sorted before #99

Open felixfbecker opened 6 years ago

felixfbecker commented 6 years ago

This means jsonlint can't be used to verify that object keys are sorted.

prantlf commented 5 years ago

The options --sort-keys is an additional option for parsing and validation. Only parsing and validation affect the exit code. If the JSON data were actually sorted, or if the sorting had no effect on already sorted content , has no effect on the exit code.

If you want to verify, or rather ensure, that object keys are sorted, you can use both --sort-keys and --in-place' options together. If the file does not change after executingjsonlint`, it was already sorted. Rewriting the file should not be a problem; git detects file changes automatically, for example.

kopach commented 4 years ago

I do agree with @felixfbecker. What I would expect from a linter tool is to throw an error (exit with 0) in case conditions doesn't met. So, I could use this in automated way (e.g. on CI) to force some codding standards. linters like eslint or tslint do provide --fix option in case file overriding is needed. Any chance to have jslint exit with 0 in case keys aren't sorted?