Skip to content

Commit

Permalink
Support offenses with no location
Browse files Browse the repository at this point in the history
  • Loading branch information
pcallewaert committed Sep 18, 2024
1 parent d89ceac commit 70d28b9
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions rdjson_formatter/rdjson_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ def started(_target_files)

def file_finished(file, offenses)
offenses.each do |offense|
next if offense.location == RuboCop::Cop::Offense::NO_LOCATION

@rdjson[:diagnostics] << build_diagnostic(file, offense)
end

Expand Down Expand Up @@ -59,30 +57,36 @@ def build_diagnostic(file, offense)
diagnostic = {
message: message,
location: {
path: convert_path(file),
range: {
start: {
line: offense.location.begin.line,
column: offense.location.begin.column + 1
},
end: {
line: offense.location.end.line,
column: offense.location.end.column + 1
}
}
path: convert_path(file)
},
severity: convert_severity(offense.severity),
code: {
value: code
},
original_output: build_original_output(file, offense)
}
diagnostic[:location][:range] = build_range(offense) unless offense.location == RuboCop::Cop::Offense::NO_LOCATION

diagnostic[:suggestions] = build_suggestions(offense) if offense.correctable? && offense.corrector

diagnostic
end

# @param [RuboCop::Cop::Offense] offense
# @return [Hash]
def build_range(offense)
{
start: {
line: offense.location.begin.line,
column: offense.location.begin.column + 1
},
end: {
line: offense.location.end.line,
column: offense.location.end.column + 1
}
}
end

# @param [RuboCop::Cop::Offense] offense
# @return [Array{Hash}]
def build_suggestions(offense)
Expand Down

0 comments on commit 70d28b9

Please sign in to comment.