Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/command_lint.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
}

if (output_json) {
std::sort(errors_array.as_array().begin(), errors_array.as_array().end(),
[](const sourcemeta::core::JSON &left,
const sourcemeta::core::JSON &right) {
const auto left_path_str = left.at("path").to_string();
const auto right_path_str = right.at("path").to_string();
if (left_path_str != right_path_str) {
return left_path_str < right_path_str;
}

const auto &left_pos = left.at("position");
const auto &right_pos = right.at("position");

if (left_pos.is_null())
return false;
if (right_pos.is_null())
return true;

return left_pos.front().to_integer() <
right_pos.front().to_integer();
});

auto output_json_object = sourcemeta::core::JSON::make_object();
output_json_object.assign("valid", sourcemeta::core::JSON{result});

Expand Down
8 changes: 4 additions & 4 deletions test/lint/fail_lint_directory_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ cat << EOF > "$TMP/expected.json"
"id": "enum_with_type",
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types",
"description": null,
"schemaLocation": "/enum",
"position": [ 7, 3, 7, 33 ]
"schemaLocation": "/type",
"position": [ 6, 3, 6, 18 ]
},
{
"path": "$(realpath "$TMP")/schemas/foo.json",
"id": "enum_with_type",
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types",
"description": null,
"schemaLocation": "/type",
"position": [ 6, 3, 6, 18 ]
"schemaLocation": "/enum",
"position": [ 7, 3, 7, 33 ]
}
]
}
Expand Down
8 changes: 4 additions & 4 deletions test/lint/fail_lint_json.sh
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@ cat << EOF > "$TMP/expected.json"
"id": "enum_with_type",
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types",
"description": null,
"schemaLocation": "/enum",
"position": [ 6, 3, 6, 19 ]
"schemaLocation": "/type",
"position": [ 5, 3, 5, 18 ]
},
{
"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",
"description": null,
"schemaLocation": "/type",
"position": [ 5, 3, 5, 18 ]
"schemaLocation": "/enum",
"position": [ 6, 3, 6, 19 ]
}
]
}
Expand Down