Skip to content

Commit 231a481

Browse files
committed
Truncate markdown results
1 parent 17d953d commit 231a481

File tree

5 files changed

+64
-35
lines changed

5 files changed

+64
-35
lines changed

CHANGELOG.md

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

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

1212
##### Bug Fixes
1313

Sources/Configuration/OutputFormat.swift

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

1212
public static let `default` = OutputFormat.xcode
1313

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import Configuration
2+
import SystemPackage
3+
4+
final class GitHubMarkdownFormatter: 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 visibleResults = results.prefix(2).flatMap { format($0) }
18+
let expandableResults = results.dropFirst(2).flatMap { format($0) }
19+
let title = results.count == 1 ? "Result" : "Results"
20+
21+
var markdown = """
22+
| \(results.count) \(title) |
23+
| :- |
24+
\(visibleResults.joined(separator: "\n"))
25+
"""
26+
27+
if !expandableResults.isEmpty {
28+
let expandableTitle = expandableResults.count == 1 ? "result" : "results"
29+
markdown += """
30+
31+
<details>
32+
<summary>Show remaining \(expandableResults.count) \(expandableTitle)</summary>
33+
<br>
34+
35+
| |
36+
| :- |
37+
\(expandableResults.joined(separator: "\n"))
38+
39+
</details>
40+
"""
41+
}
42+
43+
return markdown
44+
}
45+
46+
// MARK: - Private
47+
48+
private func format(_ result: ScanResult) -> [String] {
49+
describe(result, colored: false).map { location, description in
50+
"| **\(description)**<br>\(locationDescription(location)) |"
51+
}
52+
}
53+
}
54+
55+
func lol1() {}
56+
func lol2() {}
57+
func lol3() {}
58+
func lol4() {}
59+
func lol5() {}
60+
func lol6() {}

Sources/PeripheryKit/Results/MarkdownFormatter.swift

Lines changed: 0 additions & 31 deletions
This file was deleted.

Sources/PeripheryKit/Results/OutputFormatter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ public extension OutputFormat {
110110
CheckstyleFormatter.self
111111
case .githubActions:
112112
GitHubActionsFormatter.self
113-
case .markdown:
114-
MarkdownFormatter.self
113+
case .githubMarkdown:
114+
GitHubMarkdownFormatter.self
115115
}
116116
}
117117
}

0 commit comments

Comments
 (0)