-
Notifications
You must be signed in to change notification settings - Fork 37
Support top-level custom linter rules #795
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,5 @@ | ||
| vendorpull https://github.com/sourcemeta/vendorpull 1dcbac42809cf87cb5b045106b863e17ad84ba02 | ||
| core https://github.com/sourcemeta/core 367f6ef45c8e8f05269d65d98dab155505f39ccb | ||
| jsonbinpack https://github.com/sourcemeta/jsonbinpack 183f333e0e032ebf0a397b5d66ed504c44a0a59f | ||
| blaze https://github.com/sourcemeta/blaze 18618eccba9609f8beb5563ce57b32ec551f39bf | ||
| blaze https://github.com/sourcemeta/blaze 9d13de453c340797d3214dc12e7d9382f7f3fb47 | ||
| ctrf https://github.com/ctrf-io/ctrf 93ea827d951390190171d37443bff169cf47c808 |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -34,7 +34,8 @@ The `jsonschema.json` file format looks like this: | |||||
| ], | ||||||
| "lint": { | ||||||
| "rules": [ | ||||||
| "./rules/require_type.json" | ||||||
| "./rules/require_type.json", | ||||||
| { "path": "./rules/require_id.json", "topLevel": true } | ||||||
| ] | ||||||
| } | ||||||
| } | ||||||
|
|
@@ -61,7 +62,7 @@ describes the available configuration options: | |||||
| | `resolve` | Object | A mapping of URIs to local file paths or other URIs for schema resolution remapping. Lookups are non-transitive: the value of a matching entry is the final target and is not itself looked up in `resolve` again | `{}` | | ||||||
| | `dependencies` | Object | A mapping of URIs to relative file paths for external schema dependencies to install (see [`jsonschema install`](./install.markdown)) | `{}` | | ||||||
| | `lint` | Object | Lint configuration | `{}` | | ||||||
| | `lint.rules` | String[] | Paths to custom lint rule schemas relative to `jsonschema.json` (see [lint](./lint.markdown)) | `[]` | | ||||||
| | `lint.rules` | String[] / Object[] | Paths to custom lint rule schemas relative to `jsonschema.json` (see [lint](./lint.markdown)). An entry may also be an object with a required `path` string property and an optional `topLevel` boolean property (defaults to `false`) that makes the rule only run against the document root | `[]` | | ||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P2: The new type notation Prompt for AI agents
Suggested change
|
||||||
|
|
||||||
| Lookup Algorithm | ||||||
| ---------------- | ||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/jsonschema.json" | ||
| { | ||
| "lint": { | ||
| "rules": [ 1 ] | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| cd "$TMP" | ||
| "$1" lint "$TMP/schema.json" \ | ||
| > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| # Other input error | ||
| test "$EXIT_CODE" = "6" | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: The values in the lint rules array must be strings or objects | ||
| at file path $(realpath "$TMP")/jsonschema.json | ||
| at location "/lint/rules/0" | ||
| EOF | ||
|
|
||
| diff "$TMP/output.txt" "$TMP/expected.txt" | ||
|
|
||
| cd "$TMP" | ||
| "$1" lint --json "$TMP/schema.json" \ | ||
| > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| # Other input error | ||
| test "$EXIT_CODE" = "6" | ||
|
|
||
| cat << EOF > "$TMP/expected_json.txt" | ||
| { | ||
| "error": "The values in the lint rules array must be strings or objects", | ||
| "filePath": "$(realpath "$TMP")/jsonschema.json", | ||
| "location": "/lint/rules/0" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/output_json.txt" "$TMP/expected_json.txt" |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/rule.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "title": "require_id", | ||
| "description": "The root schema must declare an $id", | ||
| "required": [ "$id" ] | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/jsonschema.json" | ||
| { | ||
| "lint": { | ||
| "rules": [ | ||
| { "path": "./rule.json" } | ||
| ] | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "https://json-schema.org/draft/2020-12/schema", | ||
| "$id": "https://example.com/schema", | ||
| "type": "object", | ||
| "properties": { | ||
| "foo": { "type": "string" } | ||
| } | ||
| } | ||
| EOF | ||
|
|
||
| cd "$TMP" | ||
| "$1" lint --only require_id "$TMP/schema.json" \ | ||
| > "$TMP/output.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| # Lint violation | ||
| test "$EXIT_CODE" = "2" | ||
|
|
||
| cat << 'EOF' > "$TMP/expected.txt" | ||
| schema.json:6:5: | ||
| The root schema must declare an $id (require_id) | ||
| at location "/properties/foo" | ||
| The object value was expected to define the property "$id" | ||
| EOF | ||
|
|
||
| diff "$TMP/output.txt" "$TMP/expected.txt" | ||
|
|
||
| cd "$TMP" | ||
| "$1" lint --only require_id --json "$TMP/schema.json" \ | ||
| > "$TMP/output_json.txt" 2>&1 && EXIT_CODE="$?" || EXIT_CODE="$?" | ||
| # Lint violation | ||
| test "$EXIT_CODE" = "2" | ||
|
|
||
| cat << EOF > "$TMP/expected_json.txt" | ||
| { | ||
| "valid": false, | ||
| "health": 50, | ||
| "errors": [ | ||
| { | ||
| "path": "$(realpath "$TMP")/schema.json", | ||
| "id": "require_id", | ||
| "message": "The root schema must declare an \$id", | ||
| "description": "The object value was expected to define the property \"\$id\"", | ||
| "schemaLocation": [ "properties", "foo" ], | ||
| "position": [ 6, 5, 6, 31 ] | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/output_json.txt" "$TMP/expected_json.txt" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: After
jsonschema lint -t, Bash completion offerstypescript, which is not a valid top-level rule argument. The new alias needs alint-specific-targument completion before the existing codegen/upgrade handling.Prompt for AI agents