Add end_location to json formatter

This commit is contained in:
Vitalii Elenhaupt 2018-06-11 22:56:13 +03:00 committed by V. Elenhaupt
parent f8d14d4222
commit 23245d0e52
2 changed files with 29 additions and 1 deletions

View File

@ -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

View File

@ -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