Skip to content

Commit

Permalink
Update SwiftFormat to 510.1.0 (#645)
Browse files Browse the repository at this point in the history
  • Loading branch information
mohamede1945 authored Aug 17, 2024
1 parent d810aa2 commit 777228c
Show file tree
Hide file tree
Showing 14 changed files with 49 additions and 59 deletions.
2 changes: 1 addition & 1 deletion .swift-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.8
5.10
1 change: 1 addition & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
--disable hoistTry
--disable redundantType
--disable unusedArguments
--disable redundantReturn

# Enabled

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,11 @@ public actor DownloadBatchResponse {

for download in batch.downloads {
let request = download.request
let state: ResponseData.State
switch download.status {
let state: ResponseData.State = switch download.status {
case .completed:
state = .finished
.finished
case .downloading:
state = .inProgress
.inProgress
}
responses[request] = ResponseData(request: request, state: state, taskId: download.taskId, task: nil)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,11 +151,10 @@ actor DownloadSessionDelegate: NetworkSessionDelegate {
crasher.recordError(error, reason: "Download network error occurred")

// check if no disk space
let finalError: Error
if let error = error as? POSIXError, error.code == .ENOENT {
finalError = FileSystemError.noDiskSpace
let finalError: Error = if let error = error as? POSIXError, error.code == .ENOENT {
FileSystemError.noDiskSpace
} else {
finalError = NetworkError(error: error)
NetworkError(error: error)
}
return finalError
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,11 @@ extension Quarter {
let rub = quarterNumber - 1
let reminder = rub % 4

let fraction: String?
switch reminder {
case 1: fraction = lAndroid("quran_rob3")
case 2: fraction = lAndroid("quran_nos")
case 3: fraction = lAndroid("quran_talt_arb3")
default: fraction = nil
let fraction: String? = switch reminder {
case 1: lAndroid("quran_rob3")
case 2: lAndroid("quran_nos")
case 3: lAndroid("quran_talt_arb3")
default: nil
}

let hizbString = hizb.localizedName
Expand Down
7 changes: 3 additions & 4 deletions Domain/ReciterServiceFake/Reciter+Fixture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,9 @@ extension Reciter {
}

public func toPlistDictionary() -> [String: Any] {
let databaseName: String
switch audioType {
case .gapless(let db): databaseName = db
case .gapped: databaseName = ""
let databaseName: String = switch audioType {
case .gapless(let db): db
case .gapped: ""
}
return [
"id": id,
Expand Down
7 changes: 3 additions & 4 deletions Domain/WordTextService/Sources/WordTextService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,11 @@ public struct WordTextService {

public func textForWord(_ word: Word) async throws -> String? {
let textType = preferences.wordTextType
var text: String?
switch textType {
let text: String? = switch textType {
case .translation:
text = try await persistence.translationForWord(word)
try await persistence.translationForWord(word)
case .transliteration:
text = try await persistence.transliterationForWord(word)
try await persistence.transliterationForWord(word)
}
return text
}
Expand Down
7 changes: 3 additions & 4 deletions Features/FeaturesSupport/Errors+Description.swift
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,11 @@ import SQLitePersistence

extension FileSystemError: LocalizedError {
public var errorDescription: String? {
let text: String
switch self {
let text: String = switch self {
case .unknown:
text = l("error.message.general")
l("error.message.general")
case .noDiskSpace:
text = l("error.message.no_disk_space")
l("error.message.no_disk_space")
}
return text
}
Expand Down
7 changes: 3 additions & 4 deletions Features/WordPointerFeature/WordPointerViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -228,11 +228,10 @@ public final class WordPointerViewController: UIViewController {
hideWordPopover()
viewModel.unhighlightWord()

let goLeft: Bool
if abs(velocity.x) > 100 {
goLeft = velocity.x < 0
let goLeft: Bool = if abs(velocity.x) > 100 {
velocity.x < 0
} else {
goLeft = pointer.center.x < container.bounds.width / 2
pointer.center.x < container.bounds.width / 2
}

let finalY = max(10, min(container.bounds.height - pointer.bounds.height, velocity.y * 0.3 + pointer.frame.minY))
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
BUILD_TOOLS_DIR=./BuildTools

SWIFTFORMAT_REPO=https://github.com/nicklockwood/SwiftFormat
SWIFTFORMAT_VERSION=0.53.10
SWIFTFORMAT_VERSION=0.54.3
SWIFTFORMAT_DIR=$(BUILD_TOOLS_DIR)/SwiftFormat
SWIFTFORMAT_BIN=$(SWIFTFORMAT_DIR)/.build/release/swiftformat

Expand Down
17 changes: 8 additions & 9 deletions UI/NoorUI/Font/FontSize++.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,14 @@ extension FontSize: Strideable {

extension FontSize {
func fontSize(forMediumSize size: CGFloat) -> CGFloat {
let factor: CGFloat
switch self {
case .xxSmall: factor = 0.7 * 0.7 * 0.7
case .xSmall: factor = 0.7 * 0.7
case .small: factor = 0.7
case .medium: factor = 1
case .large: factor = 1 / 0.8
case .xLarge: factor = 1 / 0.8 / 0.8
case .xxLarge: factor = 1 / 0.8 / 0.8 / 0.8
let factor: CGFloat = switch self {
case .xxSmall: 0.7 * 0.7 * 0.7
case .xSmall: 0.7 * 0.7
case .small: 0.7
case .medium: 1
case .large: 1 / 0.8
case .xLarge: 1 / 0.8 / 0.8
case .xxLarge: 1 / 0.8 / 0.8 / 0.8
}
return size * factor
}
Expand Down
7 changes: 3 additions & 4 deletions UI/NoorUI/Pager/PageViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,10 @@ private struct _PageViewController<Element, Content>: UIViewControllerRepresenta

let previousIndex = forEach.data.firstIndex { $0 == previousSelection }
let currentIndex = forEach.data.firstIndex { $0 == selection }
let direction: UIPageViewController.NavigationDirection
if let previousIndex, let currentIndex {
direction = currentIndex < previousIndex ? .forward : .reverse
let direction: UIPageViewController.NavigationDirection = if let previousIndex, let currentIndex {
currentIndex < previousIndex ? .forward : .reverse
} else {
direction = .forward
.forward
}

pageViewController.setViewControllers([viewController], direction: direction, animated: animated)
Expand Down
11 changes: 5 additions & 6 deletions UI/UIx/UIKit/Views/BackgroundColorButton.swift
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,14 @@ open class BackgroundColorButton: UIButton {
}

private func updateBackgroundColor() {
let background: UIColor
if !isEnabled {
background = disabledBackground
let background: UIColor = if !isEnabled {
disabledBackground
} else if isHighlighted {
background = highlightedBackground
highlightedBackground
} else if isSelected {
background = selectedBackground
selectedBackground
} else {
background = normalBackground
normalBackground
}

backgroundColor = background
Expand Down
15 changes: 7 additions & 8 deletions UI/ViewConstrainer/ViewConstrainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,17 +98,16 @@ extension ViewConstrainer {
superviewFirst: Bool,
usesMargins: Bool
) -> SingleConstrainer {
let marginalAttribute: NSLayoutConstraint.Attribute
if usesMargins {
let marginalAttribute: NSLayoutConstraint.Attribute = if usesMargins {
switch attribute {
case .leading: marginalAttribute = .leadingMargin
case .trailing: marginalAttribute = .trailingMargin
case .top: marginalAttribute = .topMargin
case .bottom: marginalAttribute = .bottomMargin
default: marginalAttribute = attribute
case .leading: .leadingMargin
case .trailing: .trailingMargin
case .top: .topMargin
case .bottom: .bottomMargin
default: attribute
}
} else {
marginalAttribute = attribute
attribute
}
guard let superview = view.superview else {
fatalError("View \(view) should have been added as subview to another view before constraining it.")
Expand Down

0 comments on commit 777228c

Please sign in to comment.