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

Commit

Permalink
Handle nil paths in json_printer's sort_by (#561)
Browse files Browse the repository at this point in the history
Fix #560
  • Loading branch information
charlespwd authored Mar 7, 2022
1 parent 543c99f commit 8e9dbc0
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/theme_check/json_printer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def offenses_by_path(offenses)
styleCount: path_offenses.count { |offense| offense[:severity] == Check::SEVERITY_VALUES[:style] },
}
end
.sort_by { |o| o[:path] }
.sort_by { |o| o[:path] || Pathname.new('') }
end
end
end
24 changes: 24 additions & 0 deletions test/cli_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,20 @@ def test_check_format_json
{% assign x = 1 %}
{% assign y = 2 %}
LIQUID
"config/placeholder" => '',
"assets/placeholder" => '',
"locales/placeholder" => '',
"snippets/example.liquid" => '',
"templates/example.liquid" => <<~LIQUID,
{% assign z = 1 %}
LIQUID
".theme-check.yml" => <<~YAML,
extends: :nothing
UnusedAssign:
enabled: true
RequiredDirectories:
enabled: true
severity: suggestion
YAML
)

Expand All @@ -41,6 +48,23 @@ def test_check_format_json

assert_equal(
JSON.dump([
{
"path" => nil,
"offenses" => [
{
"check" => "RequiredDirectories",
"severity" => 1,
"start_row" => 0,
"start_column" => 0,
"end_row" => 0,
"end_column" => 0,
"message" => "Theme is missing 'sections' directory",
},
],
"errorCount" => 0,
"suggestionCount" => 1,
"styleCount" => 0,
},
{
"path" => "layout/theme.liquid",
"offenses" => [
Expand Down

0 comments on commit 8e9dbc0

Please sign in to comment.