Skip to content

Commit 787bcd0

Browse files
committed
Add markdown output format
1 parent d7d4f0a commit 787bcd0

File tree

5 files changed

+35
-0
lines changed

5 files changed

+35
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
##### Enhancements
88

99
- Added `--write-results <file>` option.
10+
- Added `markdown` output format.
1011

1112
##### Bug Fixes
1213

Sources/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,7 @@ swift_library(
158158
"PeripheryKit/Results/CsvFormatter.swift",
159159
"PeripheryKit/Results/GitHubActionsFormatter.swift",
160160
"PeripheryKit/Results/JsonFormatter.swift",
161+
"PeripheryKit/Results/MarkdownFormatter.swift",
161162
"PeripheryKit/Results/OutputDeclarationFilter.swift",
162163
"PeripheryKit/Results/OutputFormatter.swift",
163164
"PeripheryKit/Results/XcodeFormatter.swift",

Sources/Configuration/OutputFormat.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ public enum OutputFormat: String, CaseIterable {
77
case checkstyle
88
case codeclimate
99
case githubActions = "github-actions"
10+
case markdown
1011

1112
public static let `default` = OutputFormat.xcode
1213

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import Configuration
2+
import SystemPackage
3+
4+
final class MarkdownFormatter: OutputFormatter {
5+
let configuration: Configuration
6+
lazy var currentFilePath: FilePath = .current
7+
8+
init(configuration: Configuration) {
9+
self.configuration = configuration
10+
}
11+
12+
func format(_ results: [ScanResult], colored: Bool) throws -> String? {
13+
guard !results.isEmpty else {
14+
return "No unused code detected."
15+
}
16+
17+
let formattedResults = results.flatMap { result in
18+
describe(result, colored: colored).map { location, description in
19+
"| \(locationDescription(location)) | \(description) |"
20+
}
21+
}
22+
.joined(separator: "\n")
23+
24+
return """
25+
| Location | Result |
26+
| :- | :- |
27+
\(formattedResults)
28+
"""
29+
}
30+
}

Sources/PeripheryKit/Results/OutputFormatter.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public extension OutputFormat {
110110
CheckstyleFormatter.self
111111
case .githubActions:
112112
GitHubActionsFormatter.self
113+
case .markdown:
114+
MarkdownFormatter.self
113115
}
114116
}
115117
}

0 commit comments

Comments
 (0)