diff --git a/src/command_lint.cc b/src/command_lint.cc index 0fbb4bfa..fbb2e262 100644 --- a/src/command_lint.cc +++ b/src/command_lint.cc @@ -296,6 +296,13 @@ 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) { + return left.at("position").front() < + right.at("position").front(); + }); + auto output_json_object = sourcemeta::core::JSON::make_object(); output_json_object.assign("valid", sourcemeta::core::JSON{result}); diff --git a/test/lint/fail_lint_directory_json.sh b/test/lint/fail_lint_directory_json.sh index 7a0b6ee0..ef59b2c6 100755 --- a/test/lint/fail_lint_directory_json.sh +++ b/test/lint/fail_lint_directory_json.sh @@ -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 ] } ] } diff --git a/test/lint/fail_lint_json.sh b/test/lint/fail_lint_json.sh index 31e00624..2fbc7a93 100755 --- a/test/lint/fail_lint_json.sh +++ b/test/lint/fail_lint_json.sh @@ -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 ] } ] }