-
Notifications
You must be signed in to change notification settings - Fork 16
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
feat: add --json to lint command #228
Merged
jviotti
merged 14 commits into
sourcemeta:main
from
Karan-Palan:feat/add-json-output-to-lint
Mar 12, 2025
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
2312ed4
feat: add --json to lint command
Karan-Palan 3aaa6df
chore: rename to match JSON Schema standard output formats
Karan-Palan dd79b89
docs: update lint docs and add it in help
Karan-Palan bd35fec
tests: add tests for lint --fix converting single-value enum to const…
Karan-Palan 919197b
test: add tests to check --json on lint command
Karan-Palan 95284f4
fix: print normal JSON output even if --fix was passed
Karan-Palan b02234a
test: add test for --fix alongside --json
Karan-Palan a5f04b8
Merge branch 'main' into feat/add-json-output-to-lint
Karan-Palan f16d189
chore: update tests and remove fix command
Karan-Palan df8bde5
Merge branch 'feat/add-json-output-to-lint' of github.com:Karan-Palan…
Karan-Palan f8c19b3
chore: add line after #
Karan-Palan 656e887
chore: add line after # for other files
Karan-Palan 8ef07bb
Apply suggestions from code review
jviotti 6174e7d
Apply suggestions from code review
jviotti 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 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 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 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 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 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,35 @@ | ||
#!/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-04/schema#", | ||
"type": "string", | ||
"enum": [ "foo" ] | ||
} | ||
EOF | ||
|
||
"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 && CODE="$?" || CODE="$?" | ||
test "$CODE" = "1" || exit 1 | ||
|
||
cat << EOF > "$TMP/expected.json" | ||
{ | ||
"valid": false, | ||
"errors": [ | ||
{ | ||
"path": "$(realpath "$TMP")/schema.json", | ||
"id": "enum_with_type", | ||
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types", | ||
"schemaLocation": "" | ||
} | ||
] | ||
} | ||
EOF | ||
|
||
diff "$TMP/output.json" "$TMP/expected.json" |
This file contains 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,36 @@ | ||
#!/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", | ||
"enum": [ "foo" ] | ||
} | ||
EOF | ||
|
||
"$1" lint "$TMP/schema.json" --fix --json >"$TMP/output.json" 2>&1 | ||
|
||
cat << EOF > "$TMP/expected.json" | ||
{ | ||
"valid": true, | ||
"errors": [] | ||
} | ||
EOF | ||
|
||
diff "$TMP/output.json" "$TMP/expected.json" | ||
|
||
cat << 'EOF' > "$TMP/expected_fixed.json" | ||
{ | ||
"$schema": "http://json-schema.org/draft-06/schema#", | ||
"const": "foo" | ||
} | ||
EOF | ||
|
||
diff "$TMP/schema.json" "$TMP/expected_fixed.json" |
This file contains 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,26 @@ | ||
#!/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-04/schema#", | ||
"enum": [ "foo" ] | ||
} | ||
EOF | ||
|
||
"$1" lint "$TMP/schema.json" --json >"$TMP/output.json" 2>&1 | ||
|
||
cat << EOF > "$TMP/expected.json" | ||
{ | ||
"valid": true, | ||
"errors": [] | ||
} | ||
EOF | ||
|
||
diff "$TMP/output.json" "$TMP/expected.json" |
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.
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.
Can you leave a blank line after the hash bang, like other scripts? Same in the other ones you added here