Skip to content

Commit 3cf6c1a

Browse files
feat: add SwiftLint build plugin and fix all linting issues
1 parent 9d6d074 commit 3cf6c1a

File tree

8 files changed

+31
-26
lines changed

8 files changed

+31
-26
lines changed

Package.swift

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// swift-tools-version: 6.1
1+
// swift-tools-version: 6.0
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

44
import PackageDescription
@@ -13,23 +13,29 @@ let package = Package(
1313
.visionOS(.v1)
1414
],
1515
products: [
16-
// Products define the executables and libraries a package produces, making them visible to other packages.
1716
.library(
1817
name: "SwiftLRUCache",
1918
targets: ["SwiftLRUCache"]),
2019
],
20+
dependencies: [
21+
.package(url: "https://github.com/realm/SwiftLint.git", from: "0.54.0")
22+
],
2123
targets: [
22-
// Targets are the basic building blocks of a package, defining a module or a test suite.
23-
// Targets can depend on other targets in this package and products from dependencies.
2424
.target(
2525
name: "SwiftLRUCache",
2626
swiftSettings: [
2727
.enableExperimentalFeature("StrictConcurrency")
28+
],
29+
plugins: [
30+
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")
2831
]
2932
),
3033
.testTarget(
3134
name: "SwiftLRUCacheTests",
32-
dependencies: ["SwiftLRUCache"]
35+
dependencies: ["SwiftLRUCache"],
36+
plugins: [
37+
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLint")
38+
]
3339
),
3440
]
3541
)

Tests/SwiftLRUCacheTests/AdvancedOperationsTests.swift

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Foundation
44

55
@Suite("Advanced Operations Tests")
66
struct AdvancedOperationsTests {
7-
87
@Test("pop removes and returns LRU item")
98
func testPop() throws {
109
let config = try Configuration<String, Int>(max: 3)
@@ -173,7 +172,7 @@ struct AdvancedOperationsTests {
173172

174173
@Test("dump with TTL and size info")
175174
func testDumpWithMetadata() throws {
176-
var config = try Configuration<String, Data>(maxSize: 1024, ttl: 60)
175+
var config = try Configuration<String, Data>(maxSize: 1_024, ttl: 60)
177176
config.sizeCalculation = { value, _ in value.count }
178177

179178
let cache = LRUCache<String, Data>(configuration: config)
@@ -192,4 +191,4 @@ struct AdvancedOperationsTests {
192191
#expect(dump.contains("(size: 200)"))
193192
#expect(dump.contains("(TTL:")) // Should show remaining TTL
194193
}
195-
}
194+
}

Tests/SwiftLRUCacheTests/BasicLRUCacheTests.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Foundation
44

55
@Suite("Basic LRU Cache Tests")
66
struct BasicLRUCacheTests {
7-
87
@Test("Cache can be initialized with configuration")
98
func testCacheInitialization() throws {
109
let config = try Configuration<String, Int>(max: 100)
@@ -165,4 +164,4 @@ struct BasicLRUCacheTests {
165164
#expect(disposedItems[0].1 == 1)
166165
#expect(disposedItems[0].2 == .evict)
167166
}
168-
}
167+
}

Tests/SwiftLRUCacheTests/ConfigurationTests.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Foundation
44

55
@Suite("Configuration Tests")
66
struct ConfigurationTests {
7-
87
@Test("Configuration requires at least one constraint")
98
func testConfigurationRequiresConstraint() throws {
109
#expect(throws: ConfigurationError.noConstraints) {
@@ -22,7 +21,7 @@ struct ConfigurationTests {
2221

2322
@Test("Configuration accepts maxSize constraint")
2423
func testConfigurationWithMaxSize() throws {
25-
let config = try Configuration<String, String>(maxSize: 1024)
24+
let config = try Configuration<String, String>(maxSize: 1_024)
2625
#expect(config.max == nil)
2726
#expect(config.maxSize == 1024)
2827
#expect(config.ttl == nil)
@@ -38,7 +37,7 @@ struct ConfigurationTests {
3837

3938
@Test("Configuration accepts multiple constraints")
4039
func testConfigurationWithMultipleConstraints() throws {
41-
let config = try Configuration<String, String>(max: 100, maxSize: 1024, ttl: 300)
40+
let config = try Configuration<String, String>(max: 100, maxSize: 1_024, ttl: 300)
4241
#expect(config.max == 100)
4342
#expect(config.maxSize == 1024)
4443
#expect(config.ttl == 300)
@@ -111,7 +110,7 @@ struct ConfigurationTests {
111110

112111
@Test("Configuration accepts size calculation function")
113112
func testConfigurationWithSizeCalculation() throws {
114-
var config = try Configuration<String, Data>(maxSize: 1024)
113+
var config = try Configuration<String, Data>(maxSize: 1_024)
115114
config.sizeCalculation = { value, _ in
116115
value.count
117116
}
@@ -125,11 +124,13 @@ struct ConfigurationTests {
125124

126125
@Test("Configuration validates maxEntrySize")
127126
func testConfigurationMaxEntrySize() throws {
128-
var config = try Configuration<String, String>(maxSize: 1024)
127+
var config = try Configuration<String, String>(maxSize: 1_024)
129128
config.maxEntrySize = 512
130129

131130
#expect(config.maxEntrySize == 512)
132-
#expect(config.maxEntrySize! <= config.maxSize!)
131+
if let maxEntrySize = config.maxEntrySize, let maxSize = config.maxSize {
132+
#expect(maxEntrySize <= maxSize)
133+
}
133134
}
134135

135136
@Test("Configuration is a value type")
@@ -142,4 +143,4 @@ struct ConfigurationTests {
142143
#expect(config1.ttl == nil)
143144
#expect(config2.ttl == 300)
144145
}
145-
}
146+
}

Tests/SwiftLRUCacheTests/LRUCacheTests.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@ import Testing
44
@Suite("LRU Cache Integration Tests")
55
struct LRUCacheTests {}
66

7+

Tests/SwiftLRUCacheTests/NodeTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ struct NodeTests {
5252

5353
@Test("Node can store size metadata")
5454
func testNodeSizeMetadata() {
55-
let node = LRUNode<String, Data>(key: "data", value: Data(repeating: 0, count: 1024))
56-
node.size = 1024
55+
let node = LRUNode<String, Data>(key: "data", value: Data(repeating: 0, count: 1_024))
56+
node.size = 1_024
5757

58-
#expect(node.size == 1024)
58+
#expect(node.size == 1_024)
5959
}
6060

6161
@Test("Node can store TTL metadata")
@@ -105,4 +105,4 @@ struct NodeTests {
105105
#expect(node1.prev === node2)
106106
#expect(node1.next === node3)
107107
}
108-
}
108+
}

Tests/SwiftLRUCacheTests/SizeTrackingTests.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import Foundation
44

55
@Suite("Size Tracking Tests")
66
struct SizeTrackingTests {
7-
87
@Test("Cache respects maxSize constraint")
98
func testMaxSizeConstraint() throws {
109
var config = try Configuration<String, Data>(maxSize: 1024) // 1KB max
@@ -114,7 +113,7 @@ struct SizeTrackingTests {
114113
let age: Int
115114

116115
var estimatedSize: Int {
117-
return name.count + 8 // String chars + Int size
116+
name.count + 8 // String chars + Int size
118117
}
119118
}
120119

@@ -156,7 +155,7 @@ struct SizeTrackingTests {
156155

157156
@Test("Cache without size calculation defaults to count-based eviction")
158157
func testNoSizeCalculation() throws {
159-
let config = try Configuration<String, Data>(maxSize: 1024)
158+
let config = try Configuration<String, Data>(maxSize: 1_024)
160159
// No sizeCalculation provided
161160
let cache = LRUCache<String, Data>(configuration: config)
162161

@@ -226,4 +225,4 @@ struct SizeTrackingTests {
226225
#expect(cache.size == 2) // Limited by size
227226
#expect(cache.calculatedSize <= 500)
228227
}
229-
}
228+
}

Tests/SwiftLRUCacheTests/TTLTests.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,4 @@ struct TTLTests {
162162
#expect(disposedItems.count >= 2) // Both expired items should be disposed
163163
#expect(cache.size == 1) // Only key3 should remain
164164
}
165-
}
165+
}

0 commit comments

Comments
 (0)