diff --git a/spec/ameba/formatter/json_formatter_spec.cr b/spec/ameba/formatter/json_formatter_spec.cr index 287feb42..6937a314 100644 --- a/spec/ameba/formatter/json_formatter_spec.cr +++ b/spec/ameba/formatter/json_formatter_spec.cr @@ -54,6 +54,19 @@ module Ameba location["line"].should eq 1 location["column"].should eq 2 end + + it "shows issue end_location" do + s = Source.new "" + s.add_issue DummyRule.new, + Crystal::Location.new("path", 3, 3), + Crystal::Location.new("path", 5, 4), + "message" + + result = get_result [s] + end_location = result["sources"][0]["issues"][0]["end_location"] + end_location["line"].should eq 5 + end_location["column"].should eq 4 + end end context "summary" do diff --git a/src/ameba/formatter/json_formatter.cr b/src/ameba/formatter/json_formatter.cr index 9e982cdc..28f54262 100644 --- a/src/ameba/formatter/json_formatter.cr +++ b/src/ameba/formatter/json_formatter.cr @@ -19,6 +19,10 @@ module Ameba::Formatter # "column": 7, # "line": 17, # }, + # "end_location": { + # "column": 20, + # "line": 17, + # }, # "message": "Useless assignment to variable `a`", # "rule_name": "UselessAssign", # }, @@ -27,6 +31,10 @@ module Ameba::Formatter # "column": 7, # "line": 18, # }, + # "end_location": { + # "column": 8, + # "line": 18, + # }, # "message": "Useless assignment to variable `a`", # "rule_name": "UselessAssign", # }, @@ -35,6 +43,10 @@ module Ameba::Formatter # "column": 7, # "line": 19, # }, + # "location": { + # "column": 9, + # "line": 19, + # }, # "message": "Useless assignment to variable `a`", # "rule_name": "UselessAssign", # }, @@ -63,7 +75,7 @@ module Ameba::Formatter source.issues.each do |e| next if e.disabled? - json_source.issues << AsJSON::Issue.new(e.rule.name, e.location, e.message) + json_source.issues << AsJSON::Issue.new(e.rule.name, e.location, e.end_location, e.message) @result.summary.issues_count += 1 end @@ -96,6 +108,7 @@ module Ameba::Formatter record Issue, rule_name : String, location : Crystal::Location?, + end_location : Crystal::Location?, message : String do def to_json(json) json.object do @@ -103,6 +116,8 @@ module Ameba::Formatter json.field :message, message json.field :location, {line: location.try &.line_number, column: location.try &.column_number} + json.field :end_location, + {line: end_location.try &.line_number, column: end_location.try &.column_number} end end end