From 405409d56cd483c4592f943037410da1d89d6698 Mon Sep 17 00:00:00 2001 From: Gerald Burke Date: Sun, 17 Dec 2023 16:36:27 -0600 Subject: [PATCH] Include Line and Column in Location for JSON and CSV Outputs - Issue 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 --- Sources/PeripheryKit/Formatters/CsvFormatter.swift | 2 +- Sources/PeripheryKit/Formatters/JsonFormatter.swift | 4 ++-- Sources/PeripheryKit/Formatters/OutputFormatter.swift | 9 +++++++++ 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/Sources/PeripheryKit/Formatters/CsvFormatter.swift b/Sources/PeripheryKit/Formatters/CsvFormatter.swift index df7f72c60..4bcb55193 100644 --- a/Sources/PeripheryKit/Formatters/CsvFormatter.swift +++ b/Sources/PeripheryKit/Formatters/CsvFormatter.swift @@ -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 ?? "")" } } diff --git a/Sources/PeripheryKit/Formatters/JsonFormatter.swift b/Sources/PeripheryKit/Formatters/JsonFormatter.swift index 28036a7e9..ccfabc932 100644 --- a/Sources/PeripheryKit/Formatters/JsonFormatter.swift +++ b/Sources/PeripheryKit/Formatters/JsonFormatter.swift @@ -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) @@ -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) } diff --git a/Sources/PeripheryKit/Formatters/OutputFormatter.swift b/Sources/PeripheryKit/Formatters/OutputFormatter.swift index d29f28f2d..c801972a9 100644 --- a/Sources/PeripheryKit/Formatters/OutputFormatter.swift +++ b/Sources/PeripheryKit/Formatters/OutputFormatter.swift @@ -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 {