Skip to content
This repository was archived by the owner on Jul 27, 2024. It is now read-only.

Commit 8e9dbc0

Browse files
authored
Handle nil paths in json_printer's sort_by (#561)
Fix #560
1 parent 543c99f commit 8e9dbc0

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

lib/theme_check/json_printer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def offenses_by_path(offenses)
2525
styleCount: path_offenses.count { |offense| offense[:severity] == Check::SEVERITY_VALUES[:style] },
2626
}
2727
end
28-
.sort_by { |o| o[:path] }
28+
.sort_by { |o| o[:path] || Pathname.new('') }
2929
end
3030
end
3131
end

test/cli_test.rb

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,20 @@ def test_check_format_json
2525
{% assign x = 1 %}
2626
{% assign y = 2 %}
2727
LIQUID
28+
"config/placeholder" => '',
29+
"assets/placeholder" => '',
30+
"locales/placeholder" => '',
31+
"snippets/example.liquid" => '',
2832
"templates/example.liquid" => <<~LIQUID,
2933
{% assign z = 1 %}
3034
LIQUID
3135
".theme-check.yml" => <<~YAML,
3236
extends: :nothing
3337
UnusedAssign:
3438
enabled: true
39+
RequiredDirectories:
40+
enabled: true
41+
severity: suggestion
3542
YAML
3643
)
3744

@@ -41,6 +48,23 @@ def test_check_format_json
4148

4249
assert_equal(
4350
JSON.dump([
51+
{
52+
"path" => nil,
53+
"offenses" => [
54+
{
55+
"check" => "RequiredDirectories",
56+
"severity" => 1,
57+
"start_row" => 0,
58+
"start_column" => 0,
59+
"end_row" => 0,
60+
"end_column" => 0,
61+
"message" => "Theme is missing 'sections' directory",
62+
},
63+
],
64+
"errorCount" => 0,
65+
"suggestionCount" => 1,
66+
"styleCount" => 0,
67+
},
4468
{
4569
"path" => "layout/theme.liquid",
4670
"offenses" => [

0 commit comments

Comments
 (0)