Skip to content

Commit 13ce08d

Browse files
authored
feat: order lint errors by line number (#599)
See sourcemeta/studio#140 Signed-off-by: karan-palan <karanpalan007@gmail.com>
1 parent e7af7d9 commit 13ce08d

3 files changed

Lines changed: 15 additions & 8 deletions

File tree

src/command_lint.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,13 @@ auto sourcemeta::jsonschema::lint(const sourcemeta::core::Options &options)
296296
}
297297

298298
if (output_json) {
299+
std::sort(errors_array.as_array().begin(), errors_array.as_array().end(),
300+
[](const sourcemeta::core::JSON &left,
301+
const sourcemeta::core::JSON &right) {
302+
return left.at("position").front() <
303+
right.at("position").front();
304+
});
305+
299306
auto output_json_object = sourcemeta::core::JSON::make_object();
300307
output_json_object.assign("valid", sourcemeta::core::JSON{result});
301308

test/lint/fail_lint_directory_json.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,16 +42,16 @@ cat << EOF > "$TMP/expected.json"
4242
"id": "enum_with_type",
4343
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types",
4444
"description": null,
45-
"schemaLocation": "/enum",
46-
"position": [ 7, 3, 7, 33 ]
45+
"schemaLocation": "/type",
46+
"position": [ 6, 3, 6, 18 ]
4747
},
4848
{
4949
"path": "$(realpath "$TMP")/schemas/foo.json",
5050
"id": "enum_with_type",
5151
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types",
5252
"description": null,
53-
"schemaLocation": "/type",
54-
"position": [ 6, 3, 6, 18 ]
53+
"schemaLocation": "/enum",
54+
"position": [ 7, 3, 7, 33 ]
5555
}
5656
]
5757
}

test/lint/fail_lint_json.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ cat << EOF > "$TMP/expected.json"
3030
"id": "enum_with_type",
3131
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types",
3232
"description": null,
33-
"schemaLocation": "/enum",
34-
"position": [ 6, 3, 6, 19 ]
33+
"schemaLocation": "/type",
34+
"position": [ 5, 3, 5, 18 ]
3535
},
3636
{
3737
"path": "$(realpath "$TMP")/schema.json",
3838
"id": "enum_with_type",
3939
"message": "Setting \`type\` alongside \`enum\` is considered an anti-pattern, as the enumeration choices already imply their respective types",
4040
"description": null,
41-
"schemaLocation": "/type",
42-
"position": [ 5, 3, 5, 18 ]
41+
"schemaLocation": "/enum",
42+
"position": [ 6, 3, 6, 19 ]
4343
}
4444
]
4545
}

0 commit comments

Comments
 (0)