Skip to content

Reformat all JSON using prettier #2255

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

Merged
merged 1 commit into from
May 17, 2022

Conversation

ssbarnea
Copy link
Contributor

@ssbarnea ssbarnea commented May 17, 2022

This also includes sorting mapping keys in JSON files. Only the first file was manually modified, the pre-commit config, all the others were result of running it. I know that looks ugly, but it will make further contributions easier to review.

Fixes: #2248

This also includes sorting mapping keys in JSON files.

Fixes: SchemaStore#2248
@madskristensen
Copy link
Contributor

This looks great to me. @GerryFerdinandus what do you think?

@ssbarnea
Copy link
Contributor Author

@madskristensen Also please do not forget to visit https://pre-commit.ci/ sign and enable integration for this repository. That will allow it to auto-fix incoming PRs. We do this on many Ansible repositories, it is awesome as we all forget to do run it locally from time to time.

@GerryFerdinandus
Copy link
Contributor

Looks good.
Need to get used to sorting keys, "type": "object" at the bottom of the file etc. But that's fine.

@ssbarnea
Copy link
Contributor Author

Looks good. Need to get used to sorting keys, "type": "object" at the bottom of the file etc. But that's fine.

You do not really have to remember doing it, the linter will move the key to expected location even if you put it in wrong place.

@madskristensen madskristensen merged commit 6049f68 into SchemaStore:master May 17, 2022
@madskristensen
Copy link
Contributor

Thank you!!

@cidrblock
Copy link

after the fact.......... but this ^^^ is awesome..... TY everyone.

@rillig
Copy link
Contributor

rillig commented Jun 22, 2022

I don't like the new format, as it puts the title at the bottom of the file. The title and description should be at the top of the file.

Instead of sorting the properties alphabetically, they should be sorted for human readability, in this (incomplete) order:

  • title
  • description
  • type/$ref
  • properties
  • additionalProperties

I noticed that the top-level properties are sorted, but the properties at deeper levels aren't. Is that on purpose? I'm glad though that the properties properties were not sorted, as I assume most authors place them in "natural reading order".

Sorting the properties alphabetically seems to say that JSON schema files should not be viewed in a text editor, but rather only in specialized tools that automatically present the structure in a more human-friendly way.

@ssbarnea
Copy link
Contributor Author

@rillig We are aware of the downsides of alphabetical order but given the current limitations, alphabetical is better than arbitrary one as it makes hard to diff schemas and it does not produce predictable results. In the end what is "natural" for one user might not be seen such by another one. Think about it as "normalization".

Regarding future, take a look at json-schema-org/json-schema-vocabularies#7 as there is a plan to declare sorting order for schemas. Once we will agree on that, we will be able to update prettier sorter to respect them, bringing back title up.

I am aware that the sorting was not recursive and that was only due to a configuration mistake in sorter config. I was planning to correct it.

@JanKrivanek
Copy link
Contributor

Is there .editorconfig configuration capturing the styling expressed here (or at least as much of it as possible)?
It would be great to have editors respect the styling going forward (especially interested in spacing within the array definition - I'm adjusting that manually now)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standardize formatting of all json files using prettier format
6 participants