Skip to content

Commit

Permalink
Include Line and Column in Location for JSON and CSV Outputs - Issue …
Browse files Browse the repository at this point in the history
…680 (#681)

* Updates JsonFormatter to include line and column at end of location. Closes #680

* update CsvParser to include line and column in location output to match behavior of version 2.16.0

---------

Co-authored-by: Gerald Burke <[email protected]>
  • Loading branch information
geraldWilliam and geraldWilliam authored Dec 17, 2023
1 parent f821bd0 commit 405409d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Sources/PeripheryKit/Formatters/CsvFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ final class CsvFormatter: OutputFormatter {
let joinedModifiers = attributes.joined(separator: "|")
let joinedAttributes = modifiers.joined(separator: "|")
let joinedUsrs = usrs.joined(separator: "|")
let path = outputPath(location)
let path = locationDescription(location)
return "\(kind),\(name ?? ""),\(joinedModifiers),\(joinedAttributes),\(accessibility ?? ""),\(joinedUsrs),\(path),\(hint ?? "")"
}
}
4 changes: 2 additions & 2 deletions Sources/PeripheryKit/Formatters/JsonFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ final class JsonFormatter: OutputFormatter {
"accessibility": result.declaration.accessibility.value.rawValue,
"ids": Array(result.declaration.usrs),
"hints": [describe(result.annotation)],
"location": outputPath(result.declaration.location).string
"location": locationDescription(result.declaration.location)
]
jsonObject.append(object)

Expand All @@ -38,7 +38,7 @@ final class JsonFormatter: OutputFormatter {
"accessibility": "",
"ids": [ref.usr],
"hints": [redundantConformanceHint],
"location": outputPath(ref.location).string
"location": locationDescription(ref.location)
]
jsonObject.append(object)
}
Expand Down
9 changes: 9 additions & 0 deletions Sources/PeripheryKit/Formatters/OutputFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,15 @@ extension OutputFormatter {

return path
}

func locationDescription(_ location: SourceLocation) -> String {
[
outputPath(location).string,
String(location.line),
String(location.column)
]
.joined(separator: ":")
}
}

public extension OutputFormat {
Expand Down

0 comments on commit 405409d

Please sign in to comment.