Skip to content
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

chore: Normalize formatting of the JSON file #365

Merged
merged 4 commits into from
Sep 4, 2024

Conversation

blaine-arcjet
Copy link
Contributor

While working on some other PRs, I noticed that VSCode was trying to reformat a lot of this file. This is the format that it really wants to apply.

I think the comma on separate lines was supposed to make adding new entries easier but it was lost at some point. If those should remain, let me know and I can try converting the items that don't adhere to that style; however, I figured following a common editor formatting would make for less churn in future PRs.

@monperrus
Copy link
Owner

thanks for the PR, if we do that, we also need to modify the validation script in CI.

when it fails, it would give a clear error message "format is wrong, it should be XXXX".

@blaine-arcjet
Copy link
Contributor Author

Sounds good! I'll figure out how to check that in python

@blaine-arcjet
Copy link
Contributor Author

Since there are validations for python, go, and php that just validate the schema, I think this make sense as a separate validation. I'm choosing to write it in JS and run via Node because VSCode uses JSON.stringify for the formatting.

I'm also supporting a --generate flag on the script to regenerate the file with proper formatting.

Copy link
Owner

@monperrus monperrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, ok to do this in JS.

We improve documentation and we merge.

@@ -0,0 +1,21 @@
const fs = require("fs");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add some documentation at the top of the file to say what it does

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All set!


if (process.argv[2] === "--check") {
if (updated !== original) {
console.error("JSON file format is wrong. Run `node format.js --generate` to update.");
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

explain the expected format (indentation type, comma convention)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it an error log describing the format

@monperrus monperrus merged commit f7000aa into monperrus:master Sep 4, 2024
1 check passed
@monperrus
Copy link
Owner

thanks @blaine-arcjet

@blaine-arcjet blaine-arcjet deleted the phated/format branch September 4, 2024 13:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants