-
Notifications
You must be signed in to change notification settings - Fork 78
add sourcemeta jsonschema linting to pre-commit and fix lint issues #401
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
Conversation
|
Cool tool. Regarding the anti-pattern it's pointing out, we do actually (currently) depend on both "type" and "const" being present in some cases. For example, when printing the type of a parameter in generated documentation, we always look at "type" rather than calculating the inferred type from "const". That said, I see this tool also has a |
Good to know the usage, so actually having a check to make sure both are included might be useful. I tried ❯ diff profile_schema.json profile_schema.canonicalize.json
8a9
> "minProperties": 3,
11c12,14
< "const": "profile_schema.json#"
---
> "enum": [
> "profile_schema.json#"
> ]
14c17,19
< "const": "profile"
---
> "enum": [
> "profile"
> ]
18c23,24
< "type": "string"
---
> "type": "string",
> "minLength": 0But given this help description is BinPack related there's probably something to that: And for fun lint that new result: |
|
@kbroch-rivosinc, can we re-run this on main, and then work on getting it in the regression flow? |
Sure. Have you consider putting it in the pre-commit tool flow instead? We could put it in as a local hook similar to shellcheck if there isn't an existing hook defined. |
I was already assuming it was there, so yes ;) |
Right, pre-commit runs in regression-precommit :). Ok started with this: sourcemeta/jsonschema#263 Otherwise, I'll do a local hook(s). |
|
Hey there! Author of the Sourcemeta CLI here!
That is interesting. Which tool do you use? In general, If it is a blocker, we should definitely support a way to disable certain rules, which we don't support at the moment, as 99% of people out there seemed fine with the defaults.
Yes, this is something else, and we deprecated that functionality as it's mostly for internal use. The idea is to denormalise schemas for advanced static analysis. Overall, happy to work and collaborate on anything you guys need to make the CLI a good fit for your use case. Just let me know anything that is problematic and right now! As a member of the JSON Schema TSC, we are making a big push to make sure certain tools (like the CLI) fix real user's problems for real, so any feedback is REALLY appreciated. |
|
Check out v7.2.0 (https://github.com/sourcemeta/jsonschema/releases/tag/v7.2.0). It adds a |
It's in UnifiedBD, not a separate tool. It's a place where we are trying to generate and English of a schema field. We'll use "type" to say something like "it's a string" and "const" to say "that must be either "'blah', 'foo', or 'bar'". We could probably be smarter, but we aren't ;) |
Cool, thanks |
Fair enough. The new |
a8ed35f to
c6fee7d
Compare
436d2be to
b66d9a8
Compare
b66d9a8 to
f977660
Compare
|
@dhower-qc : I'm not sure what's going on here , looks like When I run locally it WAI: |
|
It looks like pre-commit is installing an older version jsonschema. You updated jsonschema in package.json, but that only applies if you run pre-commit with the container env (e.g., with I think we'll either to need to:
|
f977660 to
308d14c
Compare
308d14c to
3db0b1f
Compare
c3875e5 to
44d220e
Compare
44d220e to
c447deb
Compare
|
I figured out that this is a namespace collision between the |
|
@kbroch-rivosinc Ah, I heard that before. For what it's worth, the |
9f3c84b to
af4185c
Compare
af4185c to
22a00dc
Compare
yeah, I'm using |
|
circling back here. I tried to install/run sourcemeta jsonschema, but it seemed to hit a bug on our schemas. closing this PR for now |
|
@dhower-qc What is the bug you hit and what version of the CLI are you running? Do you have an example I can locally try? |
|
I tried running the JSON Schema CLI v11.1.1 (latest) on the tip of $ jsonschema lint --exclude const_with_type spec/schemas --ignore spec/schemas/json-schema-draft-07.json
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/csr_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location ""
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/ext_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location ""
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/inst_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location ""
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/inst_subtype_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location "/properties/name"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/inst_var_type_schema.json:
Wrapping any keyword other than `$ref` in `allOf` is unnecessary and may even introduce a minor evaluation performance overhead (unnecessary_allof_wrapper_draft)
at schema location ""
- /allOf/0/if
- /allOf/0/then
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/manual_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location "/properties/state"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/manual_version_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location "/properties/state"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/manual_version_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location "/properties/version"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/proc_cert_class_schema.json:
Setting `type` alongside `enum` is considered an anti-pattern, as the enumeration choices already imply their respective types (enum_with_type)
at schema location "/properties/processor_kind"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/proc_cert_model_schema.json:
Setting `type` alongside `enum` is considered an anti-pattern, as the enumeration choices already imply their respective types (enum_with_type)
at schema location "/properties/base"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/proc_cert_model_schema.json:
Setting `type` alongside `enum` is considered an anti-pattern, as the enumeration choices already imply their respective types (enum_with_type)
at schema location "/properties/in_scope_priv_modes/items"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/profile_family_schema.json:
In Draft 7 and older dialects, keywords sibling to $ref are never evaluated (draft_ref_siblings)
at schema location "/properties/description"
/Users/jviotti/Projects/playground/riscv-unified-db/spec/schemas/profile_family_schema.json:
Setting `type` alongside `enum` is considered an anti-pattern, as the enumeration choices already imply their respective types (enum_with_type)
at schema location "/properties/processor_kind"New releases tend to come with many bug fixes, so maybe you are just hitting some oddity from the old v9 version that was fixed already? As an aside, we have a Google Summer of Code project on the JSON Schema organisation going on right now specifically on the linter, so if you have any comments or any feedback, this is the perfect time! :) |
Just proof of concept of this tool https://github.com/sourcemeta/jsonschema
Don't expect this PR to go anywhere mostly just capturing results.
Has a lint feature that found some anti-patterns in the schema files. The
--fixoption also formats the files so I did that commit separately to make it easier to see the anti-patterns.Here's the log output: