Skip to content

Commit 0a91054

Browse files
authored
Add a lint CI (#21)
This upgrades SwiftLint to the latest version (0.59.1) from 0.53.0. So some format fixes are included. Closes #20.
1 parent ea1ae4d commit 0a91054

File tree

11 files changed

+117
-35
lines changed

11 files changed

+117
-35
lines changed

.github/workflows/test.yaml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
name: Test
19+
20+
on:
21+
push:
22+
branches:
23+
- '**'
24+
- '!dependabot/**'
25+
tags:
26+
- '**'
27+
pull_request:
28+
29+
concurrency:
30+
group: ${{ github.repository }}-${{ github.head_ref || github.sha }}-${{ github.workflow }}
31+
cancel-in-progress: true
32+
33+
permissions:
34+
contents: read
35+
36+
jobs:
37+
lint:
38+
name: Lint
39+
runs-on: ubuntu-latest
40+
timeout-minutes: 15
41+
steps:
42+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
43+
- uses: actions/setup-python@a26af69be951a213d495a4c3e4e4022e16d87065 # v5.6.0
44+
with:
45+
python-version: 3
46+
- uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3
47+
with:
48+
path: ~/.cache/pre-commit
49+
key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}
50+
restore-keys: pre-commit-
51+
- name: Install pre-commit
52+
run: |
53+
python -m pip install pre-commit
54+
- name: Run pre-commit
55+
run: |
56+
pre-commit run --show-diff-on-failure --color=always --all-files

.pre-commit-config.yaml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
18+
repos:
19+
- repo: https://github.com/realm/SwiftLint
20+
rev: 0.59.1
21+
hooks:
22+
- id: swiftlint
23+
args:
24+
- "--fix"
25+
- "--format"
26+
- "--strict"

Arrow/Package.swift

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,34 +33,34 @@ let package = Package(
3333
dependencies: [
3434
.package(url: "https://github.com/google/flatbuffers.git", branch: "v25.2.10"),
3535
.package(
36-
url: "https://github.com/apple/swift-atomics.git",
37-
.upToNextMajor(from: "1.2.0") // or `.upToNextMinor
38-
)
36+
url: "https://github.com/apple/swift-atomics.git",
37+
.upToNextMajor(from: "1.2.0") // or `.upToNextMinor
38+
)
3939
],
4040
targets: [
4141
.target(
4242
name: "ArrowC",
4343
path: "Sources/ArrowC",
4444
swiftSettings: [
45-
// build: .unsafeFlags(["-warnings-as-errors"])
45+
// build: .unsafeFlags(["-warnings-as-errors"])
4646
]
4747

4848
),
4949
.target(
5050
name: "Arrow",
5151
dependencies: ["ArrowC",
52-
.product(name: "FlatBuffers", package: "flatbuffers"),
53-
.product(name: "Atomics", package: "swift-atomics")
52+
.product(name: "FlatBuffers", package: "flatbuffers"),
53+
.product(name: "Atomics", package: "swift-atomics")
5454
],
5555
swiftSettings: [
56-
// build: .unsafeFlags(["-warnings-as-errors"])
56+
// build: .unsafeFlags(["-warnings-as-errors"])
5757
]
5858
),
5959
.testTarget(
6060
name: "ArrowTests",
6161
dependencies: ["Arrow", "ArrowC"],
6262
swiftSettings: [
63-
// build: .unsafeFlags(["-warnings-as-errors"])
63+
// build: .unsafeFlags(["-warnings-as-errors"])
6464
]
6565
)
6666
]

Arrow/Sources/Arrow/ArrowBufferBuilder.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -245,7 +245,7 @@ public class VariableBufferBuilder<T>: ValuesBufferBuilder<T>, ArrowBufferBuilde
245245

246246
binData.withUnsafeBytes { bufferPointer in
247247
let rawPointer = bufferPointer.baseAddress!
248-
self.values.rawPointer.advanced(by: Int(currentIndex))
248+
self.values.rawPointer.advanced(by: Int(currentIndex))
249249
.copyMemory(from: rawPointer, byteCount: binData.count)
250250
}
251251

Arrow/Sources/Arrow/ArrowCExporter.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ public class ArrowCExporter {
7979
public init() {}
8080

8181
public func exportType(_ cSchema: inout ArrowC.ArrowSchema, arrowType: ArrowType, name: String = "") ->
82-
Result<Bool, ArrowError> {
82+
Result<Bool, ArrowError> {
8383
do {
8484
let exportSchema = try ExportSchema(arrowType, name: name)
8585
cSchema.format = exportSchema.arrowTypeNameCstr
@@ -106,8 +106,8 @@ public class ArrowCExporter {
106106
}
107107

108108
public func exportField(_ schema: inout ArrowC.ArrowSchema, field: ArrowField) ->
109-
Result<Bool, ArrowError> {
110-
return exportType(&schema, arrowType: field.type, name: field.name)
109+
Result<Bool, ArrowError> {
110+
return exportType(&schema, arrowType: field.type, name: field.name)
111111
}
112112

113113
public func exportArray(_ cArray: inout ArrowC.ArrowArray, arrowData: ArrowData) {

Arrow/Sources/Arrow/ArrowCImporter.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public class ArrowCImporter {
5959
public init() {}
6060

6161
public func importType(_ cArrow: String, name: String = "") ->
62-
Result<ArrowField, ArrowError> {
62+
Result<ArrowField, ArrowError> {
6363
do {
6464
let type = try ArrowType.fromCDataFormatId(cArrow)
6565
return .success(ArrowField(name, type: ArrowType(type.info), isNullable: true))
@@ -69,7 +69,7 @@ public class ArrowCImporter {
6969
}
7070

7171
public func importField(_ cSchema: ArrowC.ArrowSchema) ->
72-
Result<ArrowField, ArrowError> {
72+
Result<ArrowField, ArrowError> {
7373
if cSchema.n_children > 0 {
7474
ArrowCImporter.release(cSchema)
7575
return .failure(.invalid("Children currently not supported"))

Arrow/Sources/Arrow/ArrowReaderHelper.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ private func makeFixedHolder<T>(
117117
}
118118
}
119119

120-
func makeStructHolder(
120+
func makeStructHolder(
121121
_ field: ArrowField,
122122
buffers: [ArrowBuffer],
123123
nullCount: UInt,

Arrow/Sources/Arrow/ArrowWriterHelper.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,29 +56,29 @@ func toFBType( // swiftlint:disable:this cyclomatic_complexity function_body_len
5656
switch arrowType.id {
5757
case .int8, .uint8:
5858
return .success(org_apache_arrow_flatbuf_Int.createInt(
59-
&fbb, bitWidth: 8, isSigned: infoType == ArrowType.ArrowInt8))
59+
&fbb, bitWidth: 8, isSigned: infoType == ArrowType.ArrowInt8))
6060
case .int16, .uint16:
6161
return .success(org_apache_arrow_flatbuf_Int.createInt(
62-
&fbb, bitWidth: 16, isSigned: infoType == ArrowType.ArrowInt16))
62+
&fbb, bitWidth: 16, isSigned: infoType == ArrowType.ArrowInt16))
6363
case .int32, .uint32:
6464
return .success(org_apache_arrow_flatbuf_Int.createInt(
65-
&fbb, bitWidth: 32, isSigned: infoType == ArrowType.ArrowInt32))
65+
&fbb, bitWidth: 32, isSigned: infoType == ArrowType.ArrowInt32))
6666
case .int64, .uint64:
6767
return .success(org_apache_arrow_flatbuf_Int.createInt(
68-
&fbb, bitWidth: 64, isSigned: infoType == ArrowType.ArrowInt64))
68+
&fbb, bitWidth: 64, isSigned: infoType == ArrowType.ArrowInt64))
6969
case .float:
7070
return .success(org_apache_arrow_flatbuf_FloatingPoint.createFloatingPoint(&fbb, precision: .single))
7171
case .double:
7272
return .success(org_apache_arrow_flatbuf_FloatingPoint.createFloatingPoint(&fbb, precision: .double))
7373
case .string:
7474
return .success(org_apache_arrow_flatbuf_Utf8.endUtf8(
75-
&fbb, start: org_apache_arrow_flatbuf_Utf8.startUtf8(&fbb)))
75+
&fbb, start: org_apache_arrow_flatbuf_Utf8.startUtf8(&fbb)))
7676
case .binary:
7777
return .success(org_apache_arrow_flatbuf_Binary.endBinary(
78-
&fbb, start: org_apache_arrow_flatbuf_Binary.startBinary(&fbb)))
78+
&fbb, start: org_apache_arrow_flatbuf_Binary.startBinary(&fbb)))
7979
case .boolean:
8080
return .success(org_apache_arrow_flatbuf_Bool.endBool(
81-
&fbb, start: org_apache_arrow_flatbuf_Bool.startBool(&fbb)))
81+
&fbb, start: org_apache_arrow_flatbuf_Bool.startBool(&fbb)))
8282
case .date32:
8383
let startOffset = org_apache_arrow_flatbuf_Date.startDate(&fbb)
8484
org_apache_arrow_flatbuf_Date.add(unit: .day, &fbb)

Arrow/Tests/ArrowTests/ArrayTests.swift

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -270,14 +270,14 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
270270
dateFormatter.timeStyle = .full
271271
XCTAssertTrue(
272272
dateFormatter.string(from: (structArray[0]![STIndex.date.rawValue] as? Date)!) ==
273-
dateFormatter.string(from: dateNow))
273+
dateFormatter.string(from: dateNow))
274274
}
275275

276276
func checkHolderForType(_ checkType: ArrowType) throws {
277277
let buffers = [ArrowBuffer(length: 0, capacity: 0,
278-
rawPointer: UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero)),
278+
rawPointer: UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero)),
279279
ArrowBuffer(length: 0, capacity: 0,
280-
rawPointer: UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero))]
280+
rawPointer: UnsafeMutableRawPointer.allocate(byteCount: 0, alignment: .zero))]
281281
let field = ArrowField("", type: checkType, isNullable: true)
282282
switch makeArrayHolder(field, buffers: buffers, nullCount: 0, children: nil, rbLength: 0) {
283283
case .success(let holder):
@@ -320,13 +320,13 @@ final class ArrayTests: XCTestCase { // swiftlint:disable:this type_body_length
320320

321321
let stringHBuilder: ArrowArrayHolderBuilder =
322322
(try ArrowArrayBuilders.loadStringArrayBuilder())
323-
for index in 0..<100 {
324-
if index % 10 == 9 {
325-
stringHBuilder.appendAny(nil)
326-
} else {
327-
stringHBuilder.appendAny("test" + String(index))
328-
}
329-
}
323+
for index in 0..<100 {
324+
if index % 10 == 9 {
325+
stringHBuilder.appendAny(nil)
326+
} else {
327+
stringHBuilder.appendAny("test" + String(index))
328+
}
329+
}
330330

331331
let stringHolder = try stringHBuilder.toHolder()
332332
XCTAssertEqual(stringHolder.nullCount, 10)

ArrowFlight/Sources/ArrowFlight/FlightServer.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ extension ArrowFlightServer {
8181
}
8282

8383
public func makeFlightServer(_ handler: ArrowFlightServer) -> CallHandlerProvider {
84-
return InternalFlightServer(handler)
84+
return InternalFlightServer(handler)
8585
}
8686

8787
internal final class InternalFlightServer: Arrow_Flight_Protocol_FlightServiceAsyncProvider {
@@ -189,6 +189,6 @@ internal final class InternalFlightServer: Arrow_Flight_Protocol_FlightServiceAs
189189
throw ArrowFlightError.notImplemented()
190190
}
191191

192-
internal var interceptors: Arrow_Flight_Protocol_FlightServiceServerInterceptorFactoryProtocol? { return nil }
192+
internal var interceptors: Arrow_Flight_Protocol_FlightServiceServerInterceptorFactoryProtocol? { return nil }
193193

194194
}

0 commit comments

Comments
 (0)