Skip to content

Commit

Permalink
🚨 (swiftformat): --enable hoistPatternLet
Browse files Browse the repository at this point in the history
  • Loading branch information
ladislas committed Dec 6, 2023
1 parent 9ac44af commit 1d23175
Show file tree
Hide file tree
Showing 12 changed files with 47 additions and 44 deletions.
3 changes: 3 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,9 @@

--enable hoistAwait

--enable hoistPatternLet
--patternlet hoist

# Disabled rules

--disable blankLinesBetweenImports
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class UpdateProcessTemplate: UpdateProcessProtocol {
switch completion {
case .finished:
self.currentStage.send(completion: .finished)
case .failure(let error):
case let .failure(error):
self.currentStage.send(completion: .failure(.updateProcessNotAvailable)) // only available error
}
}
Expand Down
2 changes: 1 addition & 1 deletion Apps/LekaUpdater/Sources/View/UpdateStatusDemoView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class UpdateStatusDemoViewModel: ObservableObject {
switch completion {
case .finished:
self.state = "Votre robot est maintenant à jour!"
case .failure(let error):
case let .failure(error):
self.state = "Oops, something wrong happened"

switch error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class UpdateStatusViewModel: ObservableObject {
switch completion {
case .finished:
self.updatingStatus = .updateFinished
case .failure(let error):
case let .failure(error):
self.updatingStatus = .error

switch error {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public class RobotListViewModel: ObservableObject {
.receive(on: DispatchQueue.main)
.sink(
receiveCompletion: { completion in
if case .failure(let error) = completion {
if case let .failure(error) = completion {
print("💥 ERROR: \(error)")
}
},
Expand All @@ -61,7 +61,7 @@ public class RobotListViewModel: ObservableObject {
.receive(on: DispatchQueue.main)
.sink(
receiveCompletion: { completion in
if case .failure(let error) = completion {
if case let .failure(error) = completion {
print("💥 ERROR: \(error)")
}
},
Expand Down
2 changes: 1 addition & 1 deletion Modules/BLEKit/Sources/Models/RobotPeripheral.swift
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public class RobotPeripheral: Equatable {
switch completion {
case .finished:
characteristic.onWrite?()
case .failure(let error):
case let .failure(error):
print("💥 ERROR: \(error)")
}
},
Expand Down
16 changes: 8 additions & 8 deletions Modules/ContentKit/Sources/Exercise/Exercise+Action.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,31 +34,31 @@ public extension Exercise {
var container = encoder.container(keyedBy: CodingKeys.self)

switch self {
case .ipad(let ipadAction):
case let .ipad(ipadAction):
try container.encode("ipad", forKey: .type)
var valueContainer = container.nestedContainer(keyedBy: CodingKeys.self, forKey: .value)
switch ipadAction {
case .color(let value):
case let .color(value):
try valueContainer.encode("color", forKey: .type)
try valueContainer.encode(value, forKey: .value)
case .image(let name):
case let .image(name):
try valueContainer.encode("image", forKey: .type)
try valueContainer.encode(name, forKey: .value)
case .audio(let name):
case let .audio(name):
try valueContainer.encode("audio", forKey: .type)
try valueContainer.encode(name, forKey: .value)
case .speech(let value):
case let .speech(value):
try valueContainer.encode("speech", forKey: .type)
try valueContainer.encode(value, forKey: .value)
}
case .robot(let robotAction):
case let .robot(robotAction):
try container.encode("robot", forKey: .type)
var valueContainer = container.nestedContainer(keyedBy: CodingKeys.self, forKey: .value)
switch robotAction {
case .image(let id):
case let .image(id):
try valueContainer.encode("image", forKey: .type)
try valueContainer.encode(id, forKey: .value)
case .color(let value):
case let .color(value):
try valueContainer.encode("color", forKey: .type)
try valueContainer.encode(value, forKey: .value)
case .audio:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public struct ListenThenTouchToSelectView: View {
public init(exercise: Exercise, data: ExerciseSharedData? = nil) {
guard
let payload = exercise.payload as? TouchToSelect.Payload,
case .ipad(type: .audio(let name)) = exercise.action
case let .ipad(type: .audio(name)) = exercise.action
else {
log.error("Exercise payload is not .selection and/or Exercise does not contain iPad audio action")
fatalError("💥 Exercise payload is not .selection and/or Exercise does not contain iPad audio action")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct ObserveThenTouchToSelectView: View {
public init(exercise: Exercise, data: ExerciseSharedData? = nil) {
guard
let payload = exercise.payload as? TouchToSelect.Payload,
case .ipad(type: .image(let name)) = exercise.action
case let .ipad(type: .image(name)) = exercise.action
else {
log.error("Exercise payload is not .selection and/or Exercise does not contain iPad image action")
fatalError("💥 Exercise payload is not .selection and/or Exercise does not contain iPad image action")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct RobotThenTouchToSelectView: View {
public init(exercise: Exercise, data: ExerciseSharedData? = nil) {
guard
let payload = exercise.payload as? TouchToSelect.Payload,
case .robot(let actionType) = exercise.action
case let .robot(actionType) = exercise.action
else {
log.error("Exercise payload is not .selection and/or Exercise does not contain robot action")
fatalError("💥 Exercise payload is not .selection and/or Exercise does not contain robot action")
Expand All @@ -54,7 +54,7 @@ public struct RobotThenTouchToSelectView: View {
HStack(spacing: 0) {
Button {
switch actionType {
case .color(let value):
case let .color(value):
robot.shine(.all(in: .init(from: value)))
case .audio, .image, .speech:
log.error("Action not available for robot: \(actionType)")
Expand Down
36 changes: 18 additions & 18 deletions Modules/RobotKit/Sources/Robot+Lights.swift
Original file line number Diff line number Diff line change
Expand Up @@ -94,66 +94,66 @@ public extension Robot {
var output: [[UInt8]] = [[]]

switch self {
case .all(let color):
case let .all(color):
let ears = shineFull(.ears, in: color)
let belt = shineFull(.belt, in: color)
output.append(contentsOf: [ears, belt])

case .spot(_: let position, let ids, let color):
case let .spot(_: position, ids, color):
for id in ids {
let payload = shineSpot(id, on: position, in: color)
output.append(payload)
}

case .full(let position, let color):
case let .full(position, color):
let payload = shineFull(position, in: color)
output.append(payload)

case .range(let start, let end, let color):
case let .range(start, end, color):
let payload = shineRange(from: start, to: end, in: color)
output.append(payload)

case .halfLeft(let color):
case let .halfLeft(color):
let start: UInt8 = 0
let end: UInt8 = 9
let payload = shineRange(from: start, to: end, in: color)
output.append(payload)

case .halfRight(let color):
case let .halfRight(color):
let start: UInt8 = 10
let end: UInt8 = 19
let payload = shineRange(from: start, to: end, in: color)
output.append(payload)

case .quarterFrontLeft(let color):
case let .quarterFrontLeft(color):
let start: UInt8 = 0
let end: UInt8 = 4
let payload = shineRange(from: start, to: end, in: color)
output.append(payload)

case .quarterFrontRight(let color):
case let .quarterFrontRight(color):
let start: UInt8 = 15
let end: UInt8 = 19
let payload = shineRange(from: start, to: end, in: color)
output.append(payload)

case .quarterBackLeft(let color):
case let .quarterBackLeft(color):
let start: UInt8 = 5
let end: UInt8 = 9
let payload = shineRange(from: start, to: end, in: color)
output.append(payload)

case .quarterBackRight(let color):
case let .quarterBackRight(color):
let start: UInt8 = 10
let end: UInt8 = 14
let payload = shineRange(from: start, to: end, in: color)
output.append(payload)

case .earLeft(let color):
case let .earLeft(color):
let payload = shineSpot(0, on: .ears, in: color)
output.append(payload)

case .earRight(let color):
case let .earRight(color):
let payload = shineSpot(1, on: .ears, in: color)
output.append(payload)
}
Expand Down Expand Up @@ -224,7 +224,7 @@ public extension Robot {
switch lights {
case .all:
shine(.all(in: .black))
case .full(let position, _):
case let .full(position, _):
shine(.full(position, in: .black))
case .halfLeft:
shine(.halfLeft(in: .black))
Expand All @@ -242,9 +242,9 @@ public extension Robot {
shine(.earLeft(in: .black))
case .earRight:
shine(.earRight(in: .black))
case .spot(let position, let ids, _):
case let .spot(position, ids, _):
shine(.spot(position, ids: ids, in: .black))
case .range(let start, let end, _):
case let .range(start, end, _):
shine(.range(start: start, end: end, in: .black))
}
}
Expand All @@ -254,7 +254,7 @@ public extension Robot {
switch lights {
case .all:
shine(.all(in: .black))
case .full(let position):
case let .full(position):
shine(.full(position, in: .black))
case .halfLeft:
shine(.halfLeft(in: .black))
Expand All @@ -272,9 +272,9 @@ public extension Robot {
shine(.earLeft(in: .black))
case .earRight:
shine(.earRight(in: .black))
case .spot(let postion, let ids):
case let .spot(postion, ids):
shine(.spot(postion, ids: ids, in: .black))
case .range(let start, let end):
case let .range(start, end):
shine(.range(start: start, end: end, in: .black))
}
}
Expand Down
16 changes: 8 additions & 8 deletions Modules/RobotKit/Sources/Robot+Motion.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,62 +46,62 @@ public extension Robot {
]
output.append(contentsOf: payload)

case .free(let left, let right):
case let .free(left, right):
let payload = [
setMotor(.left, speed: left, rotation: left < 0 ? .clockwise : .counterclockwise),
setMotor(.right, speed: right, rotation: right < 0 ? .clockwise : .counterclockwise),
]
output.append(contentsOf: payload)

case .forward(let speed):
case let .forward(speed):
guard speed.isInRange0to1 else { break }
let payload = [
setMotor(.left, speed: speed, rotation: .counterclockwise),
setMotor(.right, speed: speed, rotation: .counterclockwise),
]
output.append(contentsOf: payload)

case .forwardLeft(let speed):
case let .forwardLeft(speed):
guard speed.isInRange0to1 else { break }
let payload = [
setMotor(.left, speed: speed * 0.8, rotation: .counterclockwise),
setMotor(.right, speed: speed, rotation: .counterclockwise),
]
output.append(contentsOf: payload)

case .forwardRight(let speed):
case let .forwardRight(speed):
guard speed.isInRange0to1 else { break }
let payload = [
setMotor(.left, speed: speed, rotation: .counterclockwise),
setMotor(.right, speed: speed * 0.8, rotation: .counterclockwise),
]
output.append(contentsOf: payload)

case .backward(let speed):
case let .backward(speed):
guard speed.isInRange0to1 else { break }
let payload = [
setMotor(.left, speed: speed, rotation: .clockwise),
setMotor(.right, speed: speed, rotation: .clockwise),
]
output.append(contentsOf: payload)

case .backwardLeft(let speed):
case let .backwardLeft(speed):
guard speed.isInRange0to1 else { break }
let payload = [
setMotor(.left, speed: speed * 0.8, rotation: .clockwise),
setMotor(.right, speed: speed, rotation: .clockwise),
]
output.append(contentsOf: payload)

case .backwardRight(let speed):
case let .backwardRight(speed):
guard speed.isInRange0to1 else { break }
let payload = [
setMotor(.left, speed: speed, rotation: .clockwise),
setMotor(.right, speed: speed * 0.8, rotation: .clockwise),
]
output.append(contentsOf: payload)

case .spin(let rotation, let speed):
case let .spin(rotation, speed):
guard speed.isInRange0to1 else { break }
let payload = [
setMotor(
Expand Down

0 comments on commit 1d23175

Please sign in to comment.