Skip to content

Commit bf8266c

Browse files
committed
address build warnings: replace data(using:) with Data(_:.utf8); drop ArraySlice/VariableDeclSyntax IUOs; convert IIFE to if/else expression; require Sendable on Configurable to silence C.Type captures; discard unused popLast results; minor lint cleanups
1 parent 86ae3a3 commit bf8266c

22 files changed

Lines changed: 170 additions & 129 deletions
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
---
2+
# n9k-w1i
3+
title: Address build warnings (lint)
4+
status: completed
5+
type: task
6+
priority: normal
7+
created_at: 2026-05-02T23:14:23Z
8+
updated_at: 2026-05-03T03:06:48Z
9+
sync:
10+
github:
11+
issue_number: "639"
12+
synced_at: "2026-05-03T03:11:04Z"
13+
---
14+
15+
Fix lint warnings from Build sm_2026-05-02 log, excluding comment-related ones.
16+
17+
- [x] noParensAroundConditions: TokenStream+Closures.swift:200,201
18+
- [x] noImplicitlyUnwrappedOptionals: WhitespaceLinter.swift:211,236
19+
- [x] useNonOptionalDataInit: ConfigurationSchema+Generated.swift (generator change)
20+
- [x] wrapTernaryBranches: TokenStream+ControlFlow.swift:26
21+
- [x] useReduceInto: Trivia+Convenience.swift:162
22+
- [x] useFirstWhere: DropRedundantReturn.swift:120
23+
- [x] dropRedundantClosureWrapper: NoCaseNamedNone.swift
24+
- [x] noImplicitlyUnwrappedOptionals: SplitMultipleDeclsPerLine.swift:261
25+
- [x] useCommaNotAndInConditions: RuleMask.swift:250
26+
- [x] Sendable capture warnings: Configuration.swift:107,111,113
27+
- [x] deprecated init: DropRedundantSetterACL.swift:108
28+
- [x] popLast unused result: LayoutSingleLineBodies.swift:974,988,1002,1016,1030
29+
30+
31+
32+
## Summary of Changes
33+
34+
Addressed all 20 non-comment lint warnings from the build log:
35+
36+
- `TokenStream+Closures.swift`: dropped parens around boolean conditions
37+
- `WhitespaceLinter.swift`: replaced `ArraySlice!` IUOs with optionals + `?? 0` at use sites
38+
- `ConfigurationSchemaSwiftGenerator.swift` + `ConfigurationSchema+Generated.swift`: switched embedded JSON decode to `Data(string.utf8)`
39+
- `TokenStream+ControlFlow.swift`: wrapped ternary onto multiple lines
40+
- `Trivia+Convenience.swift`: converted `.reduce` to `.reduce(into:)` for COW seed
41+
- `DropRedundantReturn.swift`: collapsed `filter { ... }.first` into `first(where:)`
42+
- `NoCaseNamedNone.swift`: replaced immediately-invoked closure with `if`/`else if`/`else` expression
43+
- `SplitMultipleDeclsPerLine.swift`: replaced `varDecl: VariableDeclSyntax!` with optional + chained access
44+
- `RuleMask.swift`: replaced `&&` with `,` in if-condition
45+
- `Configurable.swift`: required `Sendable` conformance — fixes the three `C.Type` capture warnings in `Configuration.swift`
46+
- `DropRedundantSetterACL.swift`: dropped redundant `DeclModifierListSyntax(_:)` round-trip
47+
- `LayoutSingleLineBodies.swift`: discarded all five `popLast()` results with `_ =`
48+
49+
Clean build + `swift_diagnostics` run after: 1 unrelated warning remains; original 20 all gone.

.jig.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,31 @@ citations:
4040
- repo: swiftlang/swift-syntax
4141
branch: main
4242
last_checked_sha: 51c8c237beea1baa9cac64ef83cec68c6790506c
43-
last_checked_date: "2026-05-02T17:31:17Z"
43+
last_checked_date: "2026-05-03T03:09:08Z"
4444
paths:
4545
high: [Sources/**/*.swift]
4646
medium: [Package.swift]
4747
low: [.github/**, README.md, LICENSE]
4848
- repo: nicklockwood/SwiftFormat
4949
branch: main
5050
last_checked_sha: a5fa7a6a57abeb834df1b3fa43ea9133137d5ade
51-
last_checked_date: "2026-05-02T17:31:17Z"
51+
last_checked_date: "2026-05-03T03:09:08Z"
5252
paths:
5353
high: [Sources/**/*.swift]
5454
medium: [Package.swift]
5555
low: [.github/**, README.md, LICENSE]
5656
- repo: realm/SwiftLint
5757
branch: main
5858
last_checked_sha: ef026db5af6f768b44b43d5c3d744d6eabacd3db
59-
last_checked_date: "2026-05-02T17:31:17Z"
59+
last_checked_date: "2026-05-03T03:09:08Z"
6060
paths:
6161
high: ['**/*.swift']
6262
medium: [Package.swift]
6363
low: [.github/**, README.md, LICENSE]
6464
- repo: swiftlang/swift-format
6565
branch: main
6666
last_checked_sha: 4c86a1a7086b3eef3f55d2542926fa4c06fa70db
67-
last_checked_date: "2026-05-02T17:31:17Z"
67+
last_checked_date: "2026-05-03T03:09:08Z"
6868
paths:
6969
high: [Sources/**/*.swift]
7070
medium: [Package.swift]

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@
4545
- `// sm:ignore:next`; new directive scoped to the next line only ([#620](https://github.com/toba/swiftiomatic/issues/620))
4646
- `guard`/`else`; always break before `else` when conditions wrap ([#635](https://github.com/toba/swiftiomatic/issues/635))
4747

48+
### 🗜️ Tweaks
49+
50+
- Address build warnings; replace `data(using:)` with `Data(_:.utf8)`, drop IUOs, switch IIFEs to `if`/`else` expressions, mark `Configurable` `Sendable`, discard unused `popLast` results ([#639](https://github.com/toba/swiftiomatic/issues/639))
51+
4852
### 🐞 Fixes
4953

5054
- `useTrailingClosures`; anchor finding on the original pre-rewrite call instead of the detached `super.visit` result so the warning lands on the actual call site rather than line 1 ([#636](https://github.com/toba/swiftiomatic/issues/636))

Package.resolved

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

Sources/ConfigurationKit/Configurable.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ package func configurationKey(forTypeName name: String) -> String {
1515
///
1616
/// Both syntax rules and layout settings conform to this protocol, unifying the concept of
1717
/// "something in the configuration that has a key and a default."
18-
package protocol Configurable {
18+
package protocol Configurable: Sendable {
1919
/// The type of the default value for this item.
2020
associatedtype Value: Sendable & Codable & Equatable
2121

Sources/GeneratorKit/ConfigurationSchemaSwiftGenerator.swift

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,7 @@ package final class ConfigurationSchemaSwiftGenerator: FileGenerator {
2727
let json = ##\"\"\"
2828
\(schemaJSON)
2929
\"\"\"##
30-
guard let data = json.data(using: .utf8) else {
31-
fatalError("Failed to encode embedded JSON Schema — regenerate with `swift run Generator`")
32-
}
30+
let data = Data(json.utf8)
3331
let decoder = JSONDecoder()
3432
do {
3533
return try decoder.decode(JSONValue.self, from: data)

Sources/SwiftiomaticKit/Extensions/Trivia+Convenience.swift

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ extension Trivia {
159159
func trimmingSuperfluousNewlines(fromClosingBrace: Bool) -> (Trivia, Int) {
160160
var trimmed = 0
161161
var pendingNewlineCount = 0
162-
let pieces = indices.reduce([TriviaPiece]()) { partialResult, index in
162+
let pieces = indices.reduce(into: [TriviaPiece]()) { partialResult, index in
163163
let piece = self[index]
164164
// Collapse consecutive newlines into a single one
165165
if case let .newlines(count) = piece {
@@ -168,24 +168,23 @@ extension Trivia {
168168
// For the last index(newline right before the closing brace), collapse into
169169
// a single newline
170170
trimmed += count - 1
171-
return partialResult + [.newlines(1)]
171+
partialResult.append(.newlines(1))
172172
} else {
173173
pendingNewlineCount += count
174-
return partialResult
175174
}
176175
} else {
177176
if let last = partialResult.last, last.isNewline {
178177
trimmed += count
179-
return partialResult
180178
} else if index == 0 {
181179
// For leading trivia not associated with a closing brace, collapse the
182180
// first newline into a single one
183181
trimmed += count - 1
184-
return partialResult + [.newlines(1)]
182+
partialResult.append(.newlines(1))
185183
} else {
186-
return partialResult + [piece]
184+
partialResult.append(piece)
187185
}
188186
}
187+
return
189188
}
190189
// Remove spaces/tabs surrounded by newlines
191190
if piece.isSpaceOrTab,
@@ -194,20 +193,22 @@ extension Trivia {
194193
self[index - 1].isNewline,
195194
self[index + 1].isNewline
196195
{
197-
return partialResult
196+
return
198197
}
199198
// Handle pending newlines if there are any
200199
if pendingNewlineCount > 0 {
201200
if index < self.count - 1 {
202-
let newlines = TriviaPiece.newlines(pendingNewlineCount)
201+
partialResult.append(.newlines(pendingNewlineCount))
203202
pendingNewlineCount = 0
204-
return partialResult + [newlines] + [piece]
203+
partialResult.append(piece)
205204
} else {
206-
return partialResult + [.newlines(1)] + [piece]
205+
partialResult.append(.newlines(1))
206+
partialResult.append(piece)
207207
}
208+
return
208209
}
209210
// Retain other trivia pieces
210-
return partialResult + [piece]
211+
partialResult.append(piece)
211212
}
212213

213214
return (Trivia(pieces: pieces), trimmed)

Sources/SwiftiomaticKit/Layout/Tokens/TokenStream+Closures.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ extension TokenStream {
197197
// tokens' boundary characters would otherwise glue into one token
198198
// (e.g. `try await`, `if let`).
199199
if let p = prev.text.last, let c = t.text.first,
200-
(p.isLetter || p.isNumber || p == "_"),
201-
(c.isLetter || c.isNumber || c == "_")
200+
p.isLetter || p.isNumber || p == "_",
201+
c.isLetter || c.isNumber || c == "_"
202202
{
203203
text += " "
204204
}

Sources/SwiftiomaticKit/Layout/Tokens/TokenStream+ControlFlow.swift

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ extension TokenStream {
2323
// any condition wraps, every condition wraps. With a single condition, fall back to the
2424
// historical `.inconsistent` group (just so breaks around/inside aren't forced).
2525
let conditionsGroupStyle: GroupBreakStyle = node.conditions.count > 1
26-
? .consistent : .inconsistent
26+
? .consistent
27+
: .inconsistent
2728
before(
2829
node.conditions.firstToken(viewMode: .sourceAccurate),
2930
tokens: .open(conditionsGroupStyle)

Sources/SwiftiomaticKit/Layout/WhitespaceLinter.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,15 @@ package final class WhitespaceLinter {
208208

209209
// Move the offset to the first non-whitespace character.
210210
var adjustedUserIndex = userIndex
211-
var lastUserRun: ArraySlice<UTF8.CodeUnit>!
211+
var lastUserRun: ArraySlice<UTF8.CodeUnit>?
212212

213213
for (index, userRun) in userRuns.enumerated() {
214214
lastUserRun = userRun
215215
if index < userRuns.count - 1 { adjustedUserIndex += userRun.count + 1 }
216216
}
217217

218218
// Calculate the length of the user's line.
219-
let userIndent = lastUserRun.count
219+
let userIndent = lastUserRun?.count ?? 0
220220
var userLength = userIndent
221221

222222
for index in adjustedUserIndex..<userText.count {
@@ -233,15 +233,15 @@ package final class WhitespaceLinter {
233233

234234
// Move the offset to the first non-whitespace character.
235235
var adjustedFormattedIndex = formattedIndex
236-
var lastFormattedRun: ArraySlice<UTF8.CodeUnit>!
236+
var lastFormattedRun: ArraySlice<UTF8.CodeUnit>?
237237

238238
for (index, formattedRun) in formattedRuns.enumerated() {
239239
lastFormattedRun = formattedRun
240240
if index < formattedRuns.count - 1 { adjustedFormattedIndex += formattedRun.count + 1 }
241241
}
242242

243243
// Calculate the length of the formatted line.
244-
let formattedIndent = lastFormattedRun.count
244+
let formattedIndent = lastFormattedRun?.count ?? 0
245245
var formattedLength = formattedIndent
246246

247247
for index in adjustedFormattedIndex..<formattedText.count {

0 commit comments

Comments
 (0)