Skip to content

Commit 5ffc180

Browse files
committed
Add Swiftlint
1 parent e3f6a34 commit 5ffc180

File tree

216 files changed

+1837
-1698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

216 files changed

+1837
-1698
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,9 @@ jobs:
2828
run: swift build -v
2929
- name: Test
3030
run: swift test -v
31+
lint:
32+
name: Run Swiftlint
33+
runs-on: ubuntu-latest
34+
steps:
35+
- uses: actions/checkout@v4
36+
- uses: norio-nomura/[email protected]

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
11
.swiftpm
2+
3+
4+
# SwiftLint Remote Config Cache
5+
.swiftlint/RemoteConfigCache

.swiftlint.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
parent_config: https://gist.githubusercontent.com/RISCfuture/c57d132e5e0160a768df1625e20ae3b8/raw/.swiftlint.yml

Package.resolved

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let package = Package(
1515
name: "METARFormatting",
1616
targets: ["METARFormatting"]),
1717
.executable(name: "decode-metar", targets: ["DecodeMETAR"]),
18-
.executable(name: "decode-taf", targets: ["DecodeTAF"]),
18+
.executable(name: "decode-taf", targets: ["DecodeTAF"])
1919
],
2020
dependencies: [
2121
// Dependencies declare other packages that this package depends on.
@@ -24,7 +24,7 @@ let package = Package(
2424
.package(url: "https://github.com/objecthub/swift-numberkit.git", from: "2.6.0"),
2525
.package(url: "https://github.com/apple/swift-docc-plugin.git", from: "1.4.3"),
2626
.package(url: "https://github.com/apple/swift-argument-parser.git", from: "1.5.0"),
27-
.package(url: "https://github.com/Mr-Alirezaa/BuildableMacro.git", from: "0.5.0"),
27+
.package(url: "https://github.com/Mr-Alirezaa/BuildableMacro.git", from: "0.5.0")
2828
],
2929
targets: [
3030
// Targets are the basic building blocks of a package. A target can define a module or a test suite.

Sources/DecodeMETAR/DecodeMETAR.swift

Lines changed: 37 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import Foundation
21
import ArgumentParser
3-
import SwiftMETAR
2+
import Foundation
43
import METARFormatting
4+
import SwiftMETAR
55

66
@available(macOS 15.0, *)
77
@main
@@ -13,31 +13,31 @@ struct DecodeMETAR: AsyncParsableCommand {
1313
in which case it will download the latest METARs from AWC; or it can be used with
1414
a raw METAR string, in which case that string will be parsed.
1515
""")
16-
16+
1717
@Argument(help: "The ICAO code of an airport, or a METAR string to decode")
18-
var airportCodeOrMETAR: String? = nil
19-
20-
@Option(name: [.customLong("metar-url"), .short], help: "The URL to load the METAR CSV from.", transform: { URL(string: $0)! })
18+
var airportCodeOrMETAR: String?
19+
20+
@Option(name: [.customLong("metar-url"), .short], help: "The URL to load the METAR CSV from.", transform: { .init(string: $0)! })
2121
var METAR_URL = URL(string: "https://aviationweather.gov/data/cache/metars.cache.csv")!
22-
22+
2323
@Flag(name: .long, inversion: .prefixedNo, help: "Include raw METAR text")
2424
var raw = false
25-
25+
2626
@Flag(name: .shortAndLong, inversion: .prefixedNo, help: "Include remarks")
2727
var remarks = true
28-
28+
2929
@Flag(name: .long, help: "Parse and decode all METARs (!)")
3030
var all = false
31-
31+
3232
@Flag(name: .long, help: "Only show stations with parsing errors (intended to be used with `--all`")
3333
var errorsOnly = false
34-
34+
3535
private var session: URLSession { .init(configuration: .ephemeral) }
36-
36+
3737
func run() async throws {
3838
try await all ? parseAll() : parsePrompt()
3939
}
40-
40+
4141
private func parseAll() async throws {
4242
let METARs = try await loadMETARs { raw, error in
4343
print(raw)
@@ -50,50 +50,50 @@ struct DecodeMETAR: AsyncParsableCommand {
5050
}
5151
}
5252
}
53-
53+
5454
private func parsePrompt() async throws {
5555
let airportCodeOrMETAR = promptMETAR()
5656
let metar = try await airportCodeOrMETAR.count == 4 ? parse(code: airportCodeOrMETAR) : parse(raw: airportCodeOrMETAR)
5757
printMETAR(metar)
5858
}
59-
59+
6060
private func promptMETAR() -> String {
6161
var airportCodeOrMETAR = self.airportCodeOrMETAR
62-
62+
6363
while airportCodeOrMETAR == nil || airportCodeOrMETAR!.isEmpty {
6464
print("Enter airport code or METAR: ", terminator: "")
6565
airportCodeOrMETAR = readLine(strippingNewline: true)
6666
}
67-
67+
6868
return airportCodeOrMETAR!
6969
}
70-
70+
7171
private func parse(code: String) async throws -> METAR {
7272
guard let metar = try await getMETAR(airportCode: code) else {
7373
throw Errors.unknownAirportID(code)
7474
}
7575
return metar
7676
}
77-
77+
7878
private func parse(raw: String) async throws -> METAR {
7979
try await METAR.from(string: raw)
8080
}
81-
82-
private func loadMETARs(errorHandler: ((String, Swift.Error) throws -> Void)) async throws -> Dictionary<String, METAR> {
81+
82+
private func loadMETARs(errorHandler: ((String, Swift.Error) throws -> Void)) async throws -> [String: METAR] {
8383
print("Loading METARs…")
8484
print()
85-
85+
8686
let (data, response) = try await session.bytes(from: METAR_URL)
8787
guard let response = response as? HTTPURLResponse else {
8888
throw Errors.badResponse(response)
8989
}
90-
guard response.statusCode/100 == 2 else {
90+
guard response.statusCode / 100 == 2 else {
9191
throw Errors.badStatus(response: response)
9292
}
93-
94-
var METARs = Dictionary<String, METAR>()
93+
94+
var METARs = [String: METAR]()
9595
for try await line in data.lines {
96-
guard let range = line.rangeOfCharacter(from: CharacterSet(charactersIn: ",")) else { continue }
96+
guard let range = line.rangeOfCharacter(from: CharacterSet(charactersIn: ",")) else { continue }
9797
let string = String(line[line.startIndex..<range.lowerBound])
9898
guard string.starts(with: "K") else { continue }
9999
do {
@@ -103,26 +103,26 @@ struct DecodeMETAR: AsyncParsableCommand {
103103
try errorHandler(string, error)
104104
}
105105
}
106-
106+
107107
return METARs
108108
}
109-
109+
110110
private func getMETAR(airportCode: String) async throws -> METAR? {
111-
let METARs = try await loadMETARs { raw, error in
111+
let METARs = try await loadMETARs { raw, _ in
112112
if raw.starts(with: airportCode) {
113113
throw Errors.badMETAR(raw: raw)
114114
}
115115
}
116-
116+
117117
return METARs[airportCode]
118118
}
119-
119+
120120
private func printMETAR(_ metar: METAR) {
121121
print("Airport: \(metar.stationID)")
122122
if raw, let text = metar.text {
123123
print(text)
124124
}
125-
125+
126126
lprint("Issued: \(metar.date, format: .dateTime) (\(metar.issuance, format: .issuance))")
127127
lprint("Observer: \(metar.observer, format: .observer)")
128128
if let wind = metar.wind {
@@ -149,21 +149,21 @@ struct DecodeMETAR: AsyncParsableCommand {
149149
if let altimeter = metar.altimeter?.measurement {
150150
lprint("Altimeter: \(altimeter, format: .measurement(width: .abbreviated, usage: .asProvided))")
151151
}
152-
152+
153153
if remarks {
154154
print()
155155
printRemarks(metar: metar)
156156
}
157-
157+
158158
print()
159159
}
160-
160+
161161
private func printRemarks(metar: METAR) {
162162
for remark in metar.remarks.sorted(using: RemarkComparator()) {
163163
print(RemarkEntry.FormatStyle.remark().format(remark))
164164
}
165165
}
166-
166+
167167
private func lprint(_ str: LocalizedStringResource) {
168168
print(String(localized: str))
169169
}
@@ -185,7 +185,7 @@ extension Errors: LocalizedError {
185185
case let .badMETAR(raw): "Couldn’t parse METAR: \(raw)"
186186
}
187187
}
188-
188+
189189
var failureReason: String? {
190190
switch self {
191191
case .badResponse, .badStatus: "The AWC API may have changed, or may not be functioning properly."
Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
1+
import BuildableMacro
12
import Foundation
2-
import SwiftMETAR
33
import METARFormatting
4-
import BuildableMacro
4+
import SwiftMETAR
55

66
public extension RemarkEntry {
7-
7+
88
/// Formatter for `RemarkEntry`
9-
@Buildable struct FormatStyle: Foundation.FormatStyle, Sendable {
10-
9+
@Buildable
10+
struct FormatStyle: Foundation.FormatStyle, Sendable {
11+
1112
/// The format to use when printing times.
1213
public var dateFormat = Date.FormatStyle(date: .omitted, time: .shortened)
13-
14+
1415
public func format(_ value: RemarkEntry) -> String {
1516
switch value.urgency {
1617
case .unknown: String(localized: "(?) \(value.remark, format: .remark(dateFormat: dateFormat))", comment: "unknown remark")
@@ -22,10 +23,12 @@ public extension RemarkEntry {
2223
}
2324
}
2425

26+
// swiftlint:disable missing_docs
2527
public extension FormatStyle where Self == RemarkEntry.FormatStyle {
28+
static var remark: Self { .init() }
29+
2630
static func remark(dateFormat: Date.FormatStyle? = nil) -> Self {
2731
dateFormat.map { .init(dateFormat: $0) } ?? .init()
2832
}
29-
30-
static var remark: Self { .init() }
3133
}
34+
// swiftlint:enable missing_docs

0 commit comments

Comments
 (0)