-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
consistent JSON formatting of schemas? #4072
Comments
Yes! We use prettier to format the schemas. You can run Prettier locally with However, we do have an issue where pre-commit behaves weirdly with files paths like |
Ah, that's super interesting, thanks!
and I'm wondering why some of the rules are duplicated, and why there are special rules for keys that start with a digit or a plus sign. I did a quick grep and while there are object keys that start with a digit, they're often the start of a hex string, so having a special case for a leading digit might lead to odd ordering with respect to other similar hex keys that happen to start with a letter. But I might well be misunderstanding the configuration based on a very quick scan of https://www.npmjs.com/package/prettier-plugin-sort-json (which also seems to contain the same |
Yeah looking back at the configuration, I'm noticing some of the same issues as well. The duplicated rules before and after the I believe there are two rules that start with digit and plus because they are both mean to disable the default formatting of numbers and "words". Numbers default to sorting by order and words default to sorting by lexicographic, so I think they each have to be reset individually.
That makes sense, I didn't think of that case when making the rules.
Ohh you're right, the Thanks for your feedback! The configuration can definitely use some improvement by working against these additional cases |
One thing I don't understand: AFAICS the prettier configuration seems to be set up to sort all object properties recursively. But to take an arbitrary example, when I look at the keys in |
FWIW I experimented by removing the entire That said, I'm not at all familiar with the Node ecosystem, so I may well have installed dependencies incorrectly or be running it wrongly. |
Description of the feature / enhancement.
Some of the issues (#3102 holding some examples) could potentially be addressed by an automated change that reads each schema, applies some fix, and writes it back out again. However, that kind of automated change is awkward to review if the round-trip results in a complete reformatting of the file, making the important part of the diff hard to see.
I may have missed something (I hope so) but ISTM that if all the JSON files were formatted in a consistent tooling-friendly way, then such changes would be straightforward.
As a straw man suggestion, how about running all the files through
jq .
? Then a user can always do the same thing before committing.If there is such a formatting standard in place, then perhaps it could be documented in https://github.com/SchemaStore/schemastore/blob/master/CONTRIBUTING.md.
Are you making a PR for this?
No, someone else must create the PR.
The text was updated successfully, but these errors were encountered: