mirror of
https://gitea.invidious.io/iv-org/shard-ameba.git
synced 2024-08-15 00:53:29 +00:00
Add end_location to json formatter
This commit is contained in:
parent
f8d14d4222
commit
23245d0e52
2 changed files with 29 additions and 1 deletions
|
@ -54,6 +54,19 @@ module Ameba
|
||||||
location["line"].should eq 1
|
location["line"].should eq 1
|
||||||
location["column"].should eq 2
|
location["column"].should eq 2
|
||||||
end
|
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
|
end
|
||||||
|
|
||||||
context "summary" do
|
context "summary" do
|
||||||
|
|
|
@ -19,6 +19,10 @@ module Ameba::Formatter
|
||||||
# "column": 7,
|
# "column": 7,
|
||||||
# "line": 17,
|
# "line": 17,
|
||||||
# },
|
# },
|
||||||
|
# "end_location": {
|
||||||
|
# "column": 20,
|
||||||
|
# "line": 17,
|
||||||
|
# },
|
||||||
# "message": "Useless assignment to variable `a`",
|
# "message": "Useless assignment to variable `a`",
|
||||||
# "rule_name": "UselessAssign",
|
# "rule_name": "UselessAssign",
|
||||||
# },
|
# },
|
||||||
|
@ -27,6 +31,10 @@ module Ameba::Formatter
|
||||||
# "column": 7,
|
# "column": 7,
|
||||||
# "line": 18,
|
# "line": 18,
|
||||||
# },
|
# },
|
||||||
|
# "end_location": {
|
||||||
|
# "column": 8,
|
||||||
|
# "line": 18,
|
||||||
|
# },
|
||||||
# "message": "Useless assignment to variable `a`",
|
# "message": "Useless assignment to variable `a`",
|
||||||
# "rule_name": "UselessAssign",
|
# "rule_name": "UselessAssign",
|
||||||
# },
|
# },
|
||||||
|
@ -35,6 +43,10 @@ module Ameba::Formatter
|
||||||
# "column": 7,
|
# "column": 7,
|
||||||
# "line": 19,
|
# "line": 19,
|
||||||
# },
|
# },
|
||||||
|
# "location": {
|
||||||
|
# "column": 9,
|
||||||
|
# "line": 19,
|
||||||
|
# },
|
||||||
# "message": "Useless assignment to variable `a`",
|
# "message": "Useless assignment to variable `a`",
|
||||||
# "rule_name": "UselessAssign",
|
# "rule_name": "UselessAssign",
|
||||||
# },
|
# },
|
||||||
|
@ -63,7 +75,7 @@ module Ameba::Formatter
|
||||||
|
|
||||||
source.issues.each do |e|
|
source.issues.each do |e|
|
||||||
next if e.disabled?
|
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
|
@result.summary.issues_count += 1
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -96,6 +108,7 @@ module Ameba::Formatter
|
||||||
record Issue,
|
record Issue,
|
||||||
rule_name : String,
|
rule_name : String,
|
||||||
location : Crystal::Location?,
|
location : Crystal::Location?,
|
||||||
|
end_location : Crystal::Location?,
|
||||||
message : String do
|
message : String do
|
||||||
def to_json(json)
|
def to_json(json)
|
||||||
json.object do
|
json.object do
|
||||||
|
@ -103,6 +116,8 @@ module Ameba::Formatter
|
||||||
json.field :message, message
|
json.field :message, message
|
||||||
json.field :location,
|
json.field :location,
|
||||||
{line: location.try &.line_number, column: location.try &.column_number}
|
{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
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue