-
Notifications
You must be signed in to change notification settings - Fork 24
Support formatting in the lint command using --format
#642
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
+430
−7
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,76 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "title": "Test", | ||
| "type": "string", | ||
| "$schema": "http://json-schema.org/draft-06/schema#", | ||
| "$id": "https://example.com" | ||
| } | ||
| EOF | ||
|
|
||
| cd "$TMP" | ||
| "$1" lint "$TMP/schema.json" --fix --format >"$TMP/output.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "2" || exit 1 | ||
|
|
||
| cat << 'EOF' > "$TMP/expected_output.txt" | ||
| schema.json:1:1: | ||
| Set a non-empty description at the top level of the schema to explain what the definition is about in detail (top_level_description) | ||
| at location "" | ||
| schema.json:1:1: | ||
| Set a non-empty examples array at the top level of the schema to illustrate the expected data (top_level_examples) | ||
| at location "" | ||
| EOF | ||
|
|
||
| diff "$TMP/output.txt" "$TMP/expected_output.txt" | ||
|
|
||
| cat << 'EOF' > "$TMP/expected.json" | ||
| { | ||
| "$schema": "http://json-schema.org/draft-06/schema#", | ||
| "$id": "https://example.com", | ||
| "title": "Test", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/schema.json" "$TMP/expected.json" | ||
|
|
||
| # JSON output | ||
| "$1" lint "$TMP/schema.json" --fix --format --json >"$TMP/output_json.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "2" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected_output_json.txt" | ||
| { | ||
| "valid": false, | ||
| "health": 0, | ||
| "errors": [ | ||
| { | ||
| "path": "$(realpath "$TMP")/schema.json", | ||
| "id": "top_level_description", | ||
| "message": "Set a non-empty description at the top level of the schema to explain what the definition is about in detail", | ||
| "description": null, | ||
| "schemaLocation": "", | ||
| "position": [ 1, 1, 6, 1 ] | ||
| }, | ||
| { | ||
| "path": "$(realpath "$TMP")/schema.json", | ||
| "id": "top_level_examples", | ||
| "message": "Set a non-empty examples array at the top level of the schema to illustrate the expected data", | ||
| "description": null, | ||
| "schemaLocation": "", | ||
| "position": [ 1, 1, 6, 1 ] | ||
| } | ||
| ] | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/output_json.txt" "$TMP/expected_output_json.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "http://json-schema.org/draft-06/schema#", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| "$1" lint "$TMP/schema.json" --format >"$TMP/stderr.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: The --format option requires --fix to be set | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
|
||
| # JSON error | ||
| "$1" lint "$TMP/schema.json" --format --json >"$TMP/stdout.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "The --format option requires --fix to be set" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.yaml" | ||
| $schema: http://json-schema.org/draft-06/schema# | ||
| type: string | ||
| EOF | ||
|
|
||
| "$1" lint "$TMP/schema.yaml" --fix --format >"$TMP/stderr.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: The --fix option is not supported for YAML input files | ||
| at file path $(realpath "$TMP/schema.yaml") | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
|
||
| # JSON error | ||
| "$1" lint "$TMP/schema.yaml" --fix --format --json >"$TMP/stdout.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "The --fix option is not supported for YAML input files", | ||
| "filePath": "$(realpath "$TMP/schema.yaml")" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "$schema": "http://json-schema.org/draft-06/schema#", | ||
| "type": "string" | ||
| } | ||
| EOF | ||
|
|
||
| "$1" lint "$TMP/schema.json" --fix --keep-ordering >"$TMP/stderr.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| error: The --keep-ordering option requires --format to be set | ||
| EOF | ||
|
|
||
| diff "$TMP/stderr.txt" "$TMP/expected.txt" | ||
|
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: Add a JSON variant of this failure test. After the text assertion, run the same command with --json and verify the structured error output so JSON error reporting stays consistent. (Based on your team's feedback about adding JSON variants for failure test cases.) Prompt for AI agents |
||
|
|
||
| # JSON error | ||
| "$1" lint "$TMP/schema.json" --fix --keep-ordering --json >"$TMP/stdout.txt" 2>&1 \ | ||
| && CODE="$?" || CODE="$?" | ||
| test "$CODE" = "1" || exit 1 | ||
|
|
||
| cat << EOF > "$TMP/expected.txt" | ||
| { | ||
| "error": "The --keep-ordering option requires --format to be set" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/stdout.txt" "$TMP/expected.txt" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,37 @@ | ||
| #!/bin/sh | ||
|
|
||
| set -o errexit | ||
| set -o nounset | ||
|
|
||
| TMP="$(mktemp -d)" | ||
| clean() { rm -rf "$TMP"; } | ||
| trap clean EXIT | ||
|
|
||
| cat << 'EOF' > "$TMP/schema.json" | ||
| { | ||
| "title": "Test", | ||
| "description": "Test schema", | ||
| "type": "string", | ||
| "examples": [ "foo" ], | ||
| "$schema": "http://json-schema.org/draft-06/schema#", | ||
| "const": "foo" | ||
| } | ||
| EOF | ||
|
|
||
| "$1" lint "$TMP/schema.json" --fix --format > "$TMP/output.txt" 2>&1 | ||
|
|
||
| cat << 'EOF' > "$TMP/expected_output.txt" | ||
| EOF | ||
| diff "$TMP/output.txt" "$TMP/expected_output.txt" | ||
|
|
||
| cat << 'EOF' > "$TMP/expected.json" | ||
| { | ||
| "$schema": "http://json-schema.org/draft-06/schema#", | ||
| "title": "Test", | ||
| "description": "Test schema", | ||
| "examples": [ "foo" ], | ||
| "const": "foo" | ||
| } | ||
| EOF | ||
|
|
||
| diff "$TMP/schema.json" "$TMP/expected.json" |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.