Skip to content

Commit f43023a

Browse files
swift-format (#3)
* swift-format * Update Makefile * Update Makefile * gh-workflow script * fix linter
1 parent f600cb7 commit f43023a

File tree

11 files changed

+147
-45
lines changed

11 files changed

+147
-45
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,7 @@ trim_trailing_whitespace = true
99

1010
[Makefile]
1111
indent_style = tab
12+
13+
[*.yml]
14+
indent_style = space
15+
indent_size = 2

.github/workflows/test.yml

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ jobs:
3535
target: test-ios
3636
steps:
3737
- name: Checkout
38-
uses: actions/checkout@v2
38+
uses: actions/checkout@v4
3939
- name: Build and test
4040
run: make ${{ matrix.target }}
4141
shell: bash
@@ -44,7 +44,15 @@ jobs:
4444
runs-on: macOS-latest
4545
steps:
4646
- name: Checkout
47-
uses: actions/checkout@v2
47+
uses: actions/checkout@v4
4848
- name: Build and test
4949
run: swift test
5050
shell: bash
51+
Lint:
52+
runs-on: macOS-latest
53+
steps:
54+
- name: Checkout
55+
uses: actions/checkout@v4
56+
- name: swift-format lint
57+
run: make lint 2>&1 | Scripts/gh-workflow.swift
58+
shell: bash

.swift-format

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"version" : 1,
3+
"indentation" : {
4+
"spaces" : 4
5+
},
6+
"tabWidth" : 4,
7+
"fileScopedDeclarationPrivacy" : {
8+
"accessLevel" : "private"
9+
},
10+
"spacesAroundRangeFormationOperators" : false,
11+
"indentConditionalCompilationBlocks" : false,
12+
"indentSwitchCaseLabels" : false,
13+
"lineBreakAroundMultilineExpressionChainComponents" : false,
14+
"lineBreakBeforeControlFlowKeywords" : false,
15+
"lineBreakBeforeEachArgument" : true,
16+
"lineBreakBeforeEachGenericRequirement" : true,
17+
"lineLength" : 120,
18+
"maximumBlankLines" : 1,
19+
"respectsExistingLineBreaks" : true,
20+
"prioritizeKeepingFunctionOutputTogether" : true,
21+
"rules" : {
22+
"AllPublicDeclarationsHaveDocumentation" : false,
23+
"AlwaysUseLiteralForEmptyCollectionInit" : false,
24+
"AlwaysUseLowerCamelCase" : false,
25+
"AmbiguousTrailingClosureOverload" : true,
26+
"BeginDocumentationCommentWithOneLineSummary" : false,
27+
"DoNotUseSemicolons" : true,
28+
"DontRepeatTypeInStaticProperties" : true,
29+
"FileScopedDeclarationPrivacy" : true,
30+
"FullyIndirectEnum" : true,
31+
"GroupNumericLiterals" : true,
32+
"IdentifiersMustBeASCII" : true,
33+
"NeverForceUnwrap" : true,
34+
"NeverUseForceTry" : true,
35+
"NeverUseImplicitlyUnwrappedOptionals" : false,
36+
"NoAssignmentInExpressions" : true,
37+
"NoCasesWithOnlyFallthrough" : true,
38+
"NoEmptyTrailingClosureParentheses" : true,
39+
"NoLabelsInCasePatterns" : true,
40+
"NoLeadingUnderscores" : false,
41+
"NoParensAroundConditions" : true,
42+
"NoVoidReturnOnFunctionSignature" : true,
43+
"OmitExplicitReturns" : true,
44+
"OneCasePerLine" : true,
45+
"OneVariableDeclarationPerLine" : true,
46+
"OnlyOneTrailingClosureArgument" : true,
47+
"OrderedImports" : true,
48+
"ReturnVoidInsteadOfEmptyTuple" : true,
49+
"UseEarlyExits" : false,
50+
"UseExplicitNilCheckInConditions" : false,
51+
"UseLetInEveryBoundCaseVariable" : false,
52+
"UseShorthandTypeNames" : true,
53+
"UseSingleLinePropertyGetter" : false,
54+
"UseSynthesizedInitializer" : false,
55+
"UseTripleSlashForDocumentationComments" : true,
56+
"UseWhereClausesInForLoops" : false,
57+
"ValidateDocumentationComments" : false
58+
}
59+
}

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ clean:
88
swift package clean
99
rm -rf $(OUTPUD_DIR)
1010

11+
# MARK: - format
12+
13+
lint:
14+
xcrun swift-format lint --recursive --strict ./
15+
16+
format:
17+
xcrun swift-format --recursive --in-place ./
18+
1119
# MARK: - Tests
1220

1321
test:

Package.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,17 @@ let package = Package(
1212
products: [
1313
.library(
1414
name: "SQLime",
15-
targets: ["SQLime"]),
15+
targets: ["SQLime"]
16+
)
1617
],
1718
targets: [
1819
.target(
1920
name: "SQLime",
20-
dependencies: []),
21+
dependencies: []
22+
),
2123
.testTarget(
2224
name: "SQLimeTests",
23-
dependencies: ["SQLime"]),
25+
dependencies: ["SQLime"]
26+
),
2427
]
2528
)

Playgrounds/Example.playground/Contents.swift

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
# 🍋 SQLime
33
*/
44
import Foundation
5-
import SQLime // open Package.swift and select Playgrounds/Example
5+
import SQLime // open Package.swift and select Playgrounds/Example
6+
67
/*:
78
## Open
89

@@ -17,12 +18,14 @@ let database = try Database.open(
1718

1819
Create table for contacts with fileds `id` and `name`.
1920
*/
20-
try database.execute("""
21-
CREATE TABLE contacts(
22-
id INT PRIMARY KEY NOT NULL,
23-
name CHAR(255)
24-
);
25-
""")
21+
try database.execute(
22+
"""
23+
CREATE TABLE contacts(
24+
id INT PRIMARY KEY NOT NULL,
25+
name CHAR(255)
26+
);
27+
"""
28+
)
2629
/*:
2730
## Insert
2831

Scripts/gh-workflow.swift

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env swift
2+
3+
// Workflow commands for GitHub Actions
4+
// https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions
5+
// Usage: xcrun swift-format lint --recursive --strict ./ 2>&1 | Scripts/gh-workflow.swift
6+
// Test: echo "Sources/SQLime/SQLParameter.swift:23:1: warning: [TrailingWhitespace] remove trailing whitespace" | Scripts/gh-workflow.swift
7+
8+
let regex = #/(?<file>.+\.swift):(?<line>\d+):(?<column>\d+): (?<severity>.+): \[(?<title>.+)\] (?<message>.+)/#
9+
while let line = readLine() {
10+
if let match = try? regex.firstMatch(in: line) {
11+
let (_, file, line, column, severity, title, message) = match.output
12+
print("::\(severity) file=\(file),line=\(line),col=\(column),title=\(title)::\(message)")
13+
} else {
14+
print(line)
15+
}
16+
}

Sources/SQLime/CString.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
extension Optional<UnsafePointer<CChar>> {
1+
extension UnsafePointer<CChar>? {
22
@inlinable
33
var string: String? {
44
self.map { String(cString: $0) }

Sources/SQLime/Database.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,10 @@ public final class Database {
9393

9494
/// Compiling an SQL statement.
9595
public func prepare(_ sql: String, parameters: [SQLParameter?]) throws -> PreparedStatement {
96-
var stmt: OpaquePointer?
96+
var stmt: OpaquePointer!
9797
let code = sqlite3_prepare_v2(db, sql, -1, &stmt, nil)
9898
try check(code)
99-
let statement = PreparedStatement(stmt: stmt!)
99+
let statement = PreparedStatement(stmt: stmt)
100100
try statement.bind(parameters: parameters)
101101
return statement
102102
}

Sources/SQLime/StatementDecoder.swift

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ final class _StatementDecoder: Decoder {
3535
self.codingPath = codingPath
3636
}
3737

38-
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key : CodingKey {
38+
func container<Key>(keyedBy type: Key.Type) throws -> KeyedDecodingContainer<Key> where Key: CodingKey {
3939
let container = KeyedContainer<Key>(context: context, codingPath: codingPath)
4040
return KeyedDecodingContainer(container)
4141
}
@@ -95,7 +95,7 @@ extension _StatementDecoder {
9595
throw DecodingError.valueNotFound(type, codingPath: codingPath + [key])
9696
}
9797
guard let number = Float(exactly: value) else {
98-
throw DecodingError.numberNotFit(type, value: value.description, codingPath: codingPath + [key])
98+
throw DecodingError.numberNotFit(type, value: value.description, path: codingPath + [key])
9999
}
100100
return number
101101
}
@@ -140,7 +140,7 @@ extension _StatementDecoder {
140140
try integer(type, forKey: key)
141141
}
142142

143-
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T : Decodable {
143+
func decode<T>(_ type: T.Type, forKey key: Key) throws -> T where T: Decodable {
144144
// TODO: Data
145145
let decoder = _StatementDecoder(context: context, codingPath: codingPath + [key])
146146
return try type.init(from: decoder)
@@ -149,7 +149,7 @@ extension _StatementDecoder {
149149
func nestedContainer<NestedKey>(
150150
keyedBy type: NestedKey.Type,
151151
forKey key: Key
152-
) throws -> KeyedDecodingContainer<NestedKey> where NestedKey : CodingKey {
152+
) throws -> KeyedDecodingContainer<NestedKey> where NestedKey: CodingKey {
153153
fatalError()
154154
}
155155

@@ -171,7 +171,7 @@ extension _StatementDecoder {
171171
throw DecodingError.valueNotFound(type, codingPath: codingPath + [key])
172172
}
173173
guard let number = type.init(exactly: value) else {
174-
throw DecodingError.numberNotFit(type, value: value.description, codingPath: codingPath + [key])
174+
throw DecodingError.numberNotFit(type, value: value.description, path: codingPath + [key])
175175
}
176176
return number
177177
}
@@ -187,7 +187,7 @@ extension _StatementDecoder {
187187
func decodeNil() -> Bool {
188188
context.statement.null(for: key)
189189
}
190-
190+
191191
func decode(_ type: Bool.Type) throws -> Bool {
192192
guard let value = context.statement.int64(for: key) else {
193193
throw DecodingError.valueNotFound(type, codingPath: codingPath)
@@ -201,64 +201,64 @@ extension _StatementDecoder {
201201
}
202202
return value
203203
}
204-
204+
205205
func decode(_ type: Double.Type) throws -> Double {
206206
guard let value = context.statement.double(for: key) else {
207207
throw DecodingError.valueNotFound(type, codingPath: codingPath)
208208
}
209209
return value
210210
}
211-
211+
212212
func decode(_ type: Float.Type) throws -> Float {
213213
guard let value = context.statement.double(for: key) else {
214214
throw DecodingError.valueNotFound(type, codingPath: codingPath)
215215
}
216216
guard let number = Float(exactly: value) else {
217-
throw DecodingError.numberNotFit(type, value: value.description, codingPath: codingPath)
217+
throw DecodingError.numberNotFit(type, value: value.description, path: codingPath)
218218
}
219219
return number
220220
}
221-
221+
222222
func decode(_ type: Int.Type) throws -> Int {
223223
try integer(type)
224224
}
225-
225+
226226
func decode(_ type: Int8.Type) throws -> Int8 {
227227
try integer(type)
228228
}
229-
229+
230230
func decode(_ type: Int16.Type) throws -> Int16 {
231231
try integer(type)
232232
}
233-
233+
234234
func decode(_ type: Int32.Type) throws -> Int32 {
235235
try integer(type)
236236
}
237-
237+
238238
func decode(_ type: Int64.Type) throws -> Int64 {
239239
try integer(type)
240240
}
241-
241+
242242
func decode(_ type: UInt.Type) throws -> UInt {
243243
try integer(type)
244244
}
245-
245+
246246
func decode(_ type: UInt8.Type) throws -> UInt8 {
247247
try integer(type)
248248
}
249-
249+
250250
func decode(_ type: UInt16.Type) throws -> UInt16 {
251251
try integer(type)
252252
}
253-
253+
254254
func decode(_ type: UInt32.Type) throws -> UInt32 {
255255
try integer(type)
256256
}
257257

258258
func decode(_ type: UInt64.Type) throws -> UInt64 {
259259
try integer(type)
260260
}
261-
261+
262262
func decode<T>(_ type: T.Type) throws -> T where T: Decodable {
263263
// TODO: Data
264264
let decoder = _StatementDecoder(context: context, codingPath: codingPath)
@@ -271,7 +271,7 @@ extension _StatementDecoder {
271271
throw DecodingError.valueNotFound(type, codingPath: codingPath)
272272
}
273273
guard let number = type.init(exactly: value) else {
274-
throw DecodingError.numberNotFit(type, value: value.description, codingPath: codingPath)
274+
throw DecodingError.numberNotFit(type, value: value.description, path: codingPath)
275275
}
276276
return number
277277
}
@@ -284,8 +284,8 @@ extension DecodingError {
284284
return DecodingError.valueNotFound(type, context)
285285
}
286286

287-
fileprivate static func numberNotFit(_ type: Any.Type, value: String, codingPath: [any CodingKey]) -> DecodingError {
288-
dataCorrupted(codingPath: codingPath, "Parsed JSON number <\(value)> does not fit in \(type).")
287+
fileprivate static func numberNotFit(_ type: Any.Type, value: String, path: [any CodingKey]) -> DecodingError {
288+
dataCorrupted(codingPath: path, "Parsed JSON number <\(value)> does not fit in \(type).")
289289
}
290290

291291
fileprivate static func dataCorrupted(codingPath: [any CodingKey], _ message: String) -> DecodingError {

0 commit comments

Comments
 (0)