Fix SwiftLint and SwiftFormat violations

- Run SwiftFormat to fix indentation, spacing, and formatting issues
- Replace CGFloat with Double and NSRect with CGRect per style guide
- Remove redundant .center alignment specifications
- Remove unnecessary @available checks for satisfied deployment targets
- Fix closure brace indentation for consistency
- Disable closure_end_indentation rule to resolve SwiftFormat conflict

All linting checks now pass with zero errors and warnings.
This commit is contained in:
Arkadiusz Fal
2025-11-15 19:42:37 +01:00
parent 97ae843013
commit 5758417293
42 changed files with 400 additions and 453 deletions

View File

@@ -7,6 +7,7 @@ disabled_rules:
- number_separator
- multiline_arguments
- implicit_return
- closure_end_indentation
excluded:
- Vendor
- Tests Apple TV

View File

@@ -687,7 +687,8 @@ final class InvidiousAPI: Service, ObservableObject, VideosAPI {
func extractXTags(from urlString: String) -> [String: String] {
guard let urlComponents = URLComponents(string: urlString),
let queryItems = urlComponents.queryItems,
let xtagsValue = queryItems.first(where: { $0.name == "xtags" })?.value else {
let xtagsValue = queryItems.first(where: { $0.name == "xtags" })?.value
else {
return [:]
}

View File

@@ -722,10 +722,10 @@ final class PipedAPI: Service, ObservableObject, VideosAPI {
}
.sorted { track1, track2 in
// Sort: ORIGINAL first, then DUBBED, then others
if track1.content == "ORIGINAL" && track2.content != "ORIGINAL" {
if track1.content == "ORIGINAL", track2.content != "ORIGINAL" {
return true
}
if track1.content != "ORIGINAL" && track2.content == "ORIGINAL" {
if track1.content != "ORIGINAL", track2.content == "ORIGINAL" {
return false
}
// If both are same type, sort by language

View File

@@ -318,7 +318,7 @@ final class NavigationModel: ObservableObject {
func multipleTapHandler() {
switch tabSelection {
case .search:
self.search.focused = true
search.focused = true
default:
print("not implemented")
}

View File

@@ -26,7 +26,7 @@ final class NetworkStateModel: ObservableObject {
}
var bufferingStateText: String? {
guard detailsAvailable && player.hasStarted else { return nil }
guard detailsAvailable, player.hasStarted else { return nil }
return String(format: "%.0f%%", bufferingState)
}

View File

@@ -190,8 +190,8 @@ final class AVPlayerBackend: PlayerBackend {
}
// After the video has ended, hitting play restarts the video from the beginning.
if currentTime?.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime() &&
currentTime!.seconds > 0 && model.playerTime.duration.seconds > 0
if currentTime?.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime(),
currentTime!.seconds > 0, model.playerTime.duration.seconds > 0
{
seek(to: 0, seekType: .loopRestart)
}

View File

@@ -247,7 +247,7 @@ final class MPVBackend: PlayerBackend {
video.captions.first { $0.code.contains(captionsDefaultLanguageCode) }
// If there are still no captions, try to get captions with the fallback language code
if captions.isNil && !captionsFallbackLanguageCode.isEmpty {
if captions.isNil, !captionsFallbackLanguageCode.isEmpty {
captions = video.captions.first { $0.code == captionsFallbackLanguageCode } ??
video.captions.first { $0.code.contains(captionsFallbackLanguageCode) }
}
@@ -369,7 +369,7 @@ final class MPVBackend: PlayerBackend {
replaceItem(self.model.preservedTime)
}
} else {
replaceItem(self.model.preservedTime)
replaceItem(model.preservedTime)
}
} else {
replaceItem(nil)
@@ -400,8 +400,8 @@ final class MPVBackend: PlayerBackend {
setRate(model.currentRate)
// After the video has ended, hitting play restarts the video from the beginning.
if let currentTime, currentTime.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime() &&
currentTime.seconds > 0 && model.playerTime.duration.seconds > 0
if let currentTime, currentTime.seconds.formattedAsPlaybackTime() == model.playerTime.duration.seconds.formattedAsPlaybackTime(),
currentTime.seconds > 0, model.playerTime.duration.seconds > 0
{
seek(to: 0, seekType: .loopRestart)
}
@@ -466,23 +466,23 @@ final class MPVBackend: PlayerBackend {
func closeItem() {
pause()
stop()
self.video = nil
self.stream = nil
video = nil
stream = nil
}
func closePiP() {}
func startControlsUpdates() {
guard model.presentingPlayer, model.controls.presentingControls, !model.controls.presentingOverlays else {
self.logger.info("ignored controls update start")
logger.info("ignored controls update start")
return
}
self.logger.info("starting controls updates")
logger.info("starting controls updates")
controlsUpdates = true
}
func stopControlsUpdates() {
self.logger.info("stopping controls updates")
logger.info("stopping controls updates")
controlsUpdates = false
}
@@ -514,7 +514,7 @@ final class MPVBackend: PlayerBackend {
self.model.updateWatch(time: currentTime)
}
self.model.updateTime(currentTime)
model.updateTime(currentTime)
}
private func stopClientUpdates() {
@@ -807,7 +807,7 @@ final class MPVBackend: PlayerBackend {
guard let stream, let video else { return }
// Validate the index is within bounds
guard index >= 0 && index < stream.audioTracks.count else {
guard index >= 0, index < stream.audioTracks.count else {
logger.error("Invalid audio track index: \(index), available tracks: \(stream.audioTracks.count)")
return
}

View File

@@ -620,7 +620,7 @@ final class PlayerModel: ObservableObject {
}
Defaults[.activeBackend] = to
self.activeBackend = to
activeBackend = to
let fromBackend: PlayerBackend = from == .appleAVPlayer ? avPlayerBackend : mpvBackend
let toBackend: PlayerBackend = to == .appleAVPlayer ? avPlayerBackend : mpvBackend
@@ -628,13 +628,13 @@ final class PlayerModel: ObservableObject {
toBackend.cancelLoads()
fromBackend.cancelLoads()
if !self.backend.canPlayAtRate(currentRate) {
currentRate = self.backend.suggestedPlaybackRates.last { $0 < currentRate } ?? 1.0
if !backend.canPlayAtRate(currentRate) {
currentRate = backend.suggestedPlaybackRates.last { $0 < currentRate } ?? 1.0
}
self.rateToRestore = Float(currentRate)
rateToRestore = Float(currentRate)
self.backend.didChangeTo()
backend.didChangeTo()
if wasPlaying {
fromBackend.pause()
@@ -664,7 +664,7 @@ final class PlayerModel: ObservableObject {
self.stream = stream
streamSelection = stream
self.upgradeToStream(stream, force: true)
upgradeToStream(stream, force: true)
return
}
@@ -1086,7 +1086,7 @@ final class PlayerModel: ObservableObject {
logger.info("entering fullscreen")
toggleFullscreen(false, showControls: showControls)
self.playingFullScreen = true
playingFullScreen = true
}
func exitFullScreen(showControls: Bool = true) {
@@ -1094,7 +1094,7 @@ final class PlayerModel: ObservableObject {
logger.info("exiting fullscreen")
toggleFullscreen(true, showControls: showControls)
self.playingFullScreen = false
playingFullScreen = false
}
func updateNowPlayingInfo() {
@@ -1284,7 +1284,7 @@ final class PlayerModel: ObservableObject {
}
private func chapterForTime(_ time: Double) -> Int? {
guard let chapters = self.videoForDisplay?.chapters else {
guard let chapters = videoForDisplay?.chapters else {
return nil
}

View File

@@ -186,11 +186,7 @@ struct ChannelVideosView: View {
.background(Color.background(scheme: colorScheme))
.focusScope(focusNamespace)
#elseif os(macOS)
if #available(macOS 12.0, *) {
return content.focusScope(focusNamespace)
} else {
return content
}
#else
return content
#endif

View File

@@ -61,7 +61,7 @@ enum Constants {
#endif
}
static var iPadSystemControlsWidth: CGFloat {
static var iPadSystemControlsWidth: Double {
50
}

View File

@@ -20,7 +20,7 @@ struct VideoDetailsOverlay: View {
}
#if os(iOS)
private var overlayLeadingPadding: CGFloat {
private var overlayLeadingPadding: Double {
// On iPad in non-fullscreen mode, add left padding for system controls
if Constants.isIPad && !Constants.isWindowFullscreen {
return Constants.iPadSystemControlsWidth + 15
@@ -28,7 +28,7 @@ struct VideoDetailsOverlay: View {
return 0
}
#else
private var overlayLeadingPadding: CGFloat {
private var overlayLeadingPadding: Double {
return 0
}
#endif

View File

@@ -140,7 +140,7 @@ final class MPVOGLView: GLKView {
glGetIntegerv(UInt32(GL_FRAMEBUFFER_BINDING), &defaultFBO!)
// Ensure the framebuffer is valid
guard defaultFBO != nil && defaultFBO! != 0 else {
guard defaultFBO != nil, defaultFBO! != 0 else {
logger.error("Invalid framebuffer ID.")
return
}

View File

@@ -64,10 +64,10 @@ struct PlaybackSettings: View {
.padding(.vertical, 10)
if player.activeBackend == .mpv || !player.avPlayerUsesSystemControls {
HStack(alignment: .center) {
HStack {
controlsHeader("Rate".localized())
Spacer()
HStack(alignment: .center, spacing: rateButtonsSpacing) {
HStack(spacing: rateButtonsSpacing) {
decreaseRateButton
#if os(tvOS)
.focused($focusedField, equals: .decreaseRate)

View File

@@ -16,7 +16,7 @@ import Foundation
player.avPlayerBackend.playerLayer
}
override init(frame frameRect: NSRect) {
override init(frame frameRect: CGRect) {
super.init(frame: frameRect)
wantsLayer = true
}

View File

@@ -256,11 +256,7 @@ struct CommentView: View {
#if os(macOS)
struct TextSelectionModifier: ViewModifier {
func body(content: Content) -> some View {
if #available(macOS 12.0, *) {
content.textSelection(.enabled)
} else {
content
}
}
}
#endif

View File

@@ -58,7 +58,6 @@ struct VideoDescription: View {
@ViewBuilder var textDescription: some View {
#if canImport(AppKit)
if #available(macOS 12.0, *) {
DescriptionWithLinks(description: description, detailsSize: detailsSize)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(expand ? 500 : collapsedLinesDescription)
@@ -67,21 +66,11 @@ struct VideoDescription: View {
.font(.system(size: 14))
.lineSpacing(3)
.allowsHitTesting(expand)
} else {
Text(description)
.frame(maxWidth: .infinity, alignment: .leading)
.lineLimit(expand ? 500 : collapsedLinesDescription)
.multilineTextAlignment(.leading)
.font(.system(size: 14))
.lineSpacing(3)
.allowsHitTesting(expand)
}
#endif
}
// If possibe convert URLs to clickable links
#if canImport(AppKit)
@available(macOS 12.0, *)
struct DescriptionWithLinks: View {
let description: String
let detailsSize: CGSize?

View File

@@ -242,11 +242,7 @@ struct QualityProfileForm: View {
#if os(macOS)
let list = filteredFormatList
if #available(macOS 12.0, *) {
list.listStyle(.inset(alternatesRowBackgrounds: true))
} else {
list.listStyle(.inset)
}
Spacer()
#else
filteredFormatList

View File

@@ -183,17 +183,10 @@ struct QualitySettings: View {
}
#if os(macOS)
if #available(macOS 12.0, *) {
List {
list
}
.listStyle(.inset(alternatesRowBackgrounds: true))
} else {
List {
list
}
.listStyle(.inset)
}
#else
list
#endif

View File

@@ -223,7 +223,6 @@ struct FeedView: View {
var header: some View {
HStack(spacing: 16) {
#if os(tvOS)
if #available(tvOS 17.0, *) {
Menu {
accountsPicker
} label: {
@@ -239,21 +238,6 @@ struct FeedView: View {
}
.opacity(feedChannelsViewVisible ? 0 : 1)
.frame(minWidth: feedChannelsViewVisible ? 0 : nil, maxWidth: feedChannelsViewVisible ? 0 : nil)
} else {
Button {
withAnimation {
self.feedChannelsViewVisible = true
self.focusedChannel = selectedChannel?.id ?? "all"
}
} label: {
Label("Channels", systemImage: "filemenu.and.selection")
.labelStyle(.iconOnly)
.imageScale(.small)
.font(.caption)
}
.opacity(feedChannelsViewVisible ? 0 : 1)
.frame(minWidth: feedChannelsViewVisible ? 0 : nil, maxWidth: feedChannelsViewVisible ? 0 : nil)
}
channelHeaderView
if selectedChannel == nil {
Spacer()

View File

@@ -58,11 +58,7 @@ struct TrendingCountry: View {
return Group {
#if os(macOS)
if #available(macOS 12.0, *) {
list.listStyle(.inset(alternatesRowBackgrounds: true))
} else {
list.listStyle(.inset)
}
#else
list
#endif

View File

@@ -9,7 +9,7 @@ struct ThumbnailView: View {
init(url: URL?) {
self.url = url
self.thumbnailExtension = Self.extractExtension(from: url)
thumbnailExtension = Self.extractExtension(from: url)
}
private static func extractExtension(from url: URL?) -> String? {

View File

@@ -341,6 +341,7 @@ struct ControlsBar_Previews: PreviewProvider {
}
// MARK: - View Extension for Conditional Modifiers
extension View {
@ViewBuilder
func `if`<Transform: View>(_ condition: Bool, transform: (Self) -> Transform) -> some View {
@@ -375,8 +376,7 @@ extension View {
.stroke(Color("ControlsBorderColor"), lineWidth: 0.5)
)
} else {
self
.background(
background(
RoundedRectangle(cornerRadius: cornerRadius)
.fill(Color.gray.opacity(0.3))
)
@@ -400,8 +400,7 @@ extension View {
.stroke(Color("ControlsBorderColor"), lineWidth: 0.5)
)
} else {
self
.background(
background(
RoundedRectangle(cornerRadius: cornerRadius)
.fill(Color.gray.opacity(0.3))
)
@@ -412,7 +411,7 @@ extension View {
}
#endif
} else {
self.background(Color.clear)
background(Color.clear)
}
}
}

View File

@@ -24,7 +24,7 @@ struct SettingsPickerModifier: ViewModifier {
// Extension to help remove picker row backgrounds
extension View {
func pickerRowStyle() -> some View {
self.buttonStyle(.plain)
buttonStyle(.plain)
.listRowBackground(Color.clear)
}
}

View File

@@ -71,11 +71,7 @@ struct InstancesSettings: View {
}
}
if #available(macOS 12.0, *) {
list.listStyle(.inset(alternatesRowBackgrounds: true))
} else {
list.listStyle(.inset)
}
}
if selectedInstance != nil, selectedInstance.app.hasFrontendURL {