-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path.parse_undocumented_json.swift
executable file
·78 lines (67 loc) · 2.2 KB
/
.parse_undocumented_json.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
import Foundation
/// The path to the JSON with the information from Jazzy.
let filePath = "docs/undocumented.json"
let url = URL(fileURLWithPath: filePath)
/// Structure to extract from the JSON.
struct UndocumentedFile: Codable {
var file: String?
var line: Int?
var symbol: String?
var symbolKind: String?
var warning: String?
}
struct JazzyWarning: Codable {
var warnings = [UndocumentedFile]()
var fileNames: [String] {
get {
let allFileNames = warnings.map { $0.file! }
return Array(Set(allFileNames))
}
}
var linesForFiles: [String: [Int]] {
get {
var lff = [String: [Int]]()
for fileName in fileNames {
var lines = [Int]()
for warning in warnings {
if warning.file == fileName {
lines.append(warning.line!)
}
}
lines.sort()
lff[fileName] = lines
}
return lff
}
}
}
var jazzyWarning = JazzyWarning()
do {
let data = try Data(contentsOf: url)
let json = try JSONSerialization.jsonObject(with: data, options: [])
if let dictionary = json as? [String: Any], let warningsArray = dictionary["warnings"] as? [Any] {
for warningArray in warningsArray {
if let warning = warningArray as? [String: Any] {
jazzyWarning.warnings.append(UndocumentedFile(
file: warning["file"] as? String,
line: warning["line"] as? Int,
symbol: warning["symbol"] as? String,
symbolKind: warning["symbol_kind"] as? String,
warning: warning["warning"] as? String
))
}
}
}
} catch {
print(error)
}
if jazzyWarning.warnings.count == 0 {
print("No undocumented objects.")
} else {
print("-------\nThe following lines contain undocumented objects:\n")
for file in jazzyWarning.linesForFiles.keys.sorted() {
let fileName = (file as NSString).lastPathComponent
print(" \(fileName): \(jazzyWarning.linesForFiles[file]!)")
}
print("-------")
}