Skip to content

Commit

Permalink
fix: resolve warnings and update swiftlint.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanStepanok committed Dec 11, 2024
1 parent f316b1c commit d489e1c
Show file tree
Hide file tree
Showing 31 changed files with 270 additions and 148 deletions.
20 changes: 15 additions & 5 deletions .github/workflows/swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: SwiftLint

on:
workflow_dispatch:

pull_request:

jobs:
Expand All @@ -11,8 +10,6 @@ jobs:
runs-on: macos-latest

concurrency:
# When running on develop, use the sha to allow all runs of this workflow to run concurrently.
# Otherwise only allow a single run of this workflow on each branch, automatically cancelling older runs.
group: ${{ github.ref == 'refs/heads/develop' && format('swiftlint-develop-{0}', github.sha) || format('swiftlint-{0}', github.ref) }}
cancel-in-progress: true

Expand All @@ -31,7 +28,20 @@ jobs:
- name: Setup environment
run:
source ci_scripts/ci_prepare_env.sh && setup_github_actions_environment
xcodes select 16.1

- name: SwiftLint
run:
bundle exec fastlane linting
run: |
bundle exec fastlane linting -- --reporter sarif --output swiftlint.report.sarif
continue-on-error: true

- name: Prepare swiftlint.report.sarif
if: success() || failure()
run: |
swift PrepareSarifToUpload.swift
- name: Upload report
uses: github/codeql-action/upload-sarif@v3
if: success() || failure()
with:
sarif_file: swiftlint.report.sarif
10 changes: 2 additions & 8 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
warning_threshold: 1
disabled_rules: # rule identifiers to exclude from running
- identifier_name
- comment_spacing
Expand Down Expand Up @@ -56,7 +57,7 @@ trailing_whitespace:
ignores_empty_lines: true

file_length:
warning: 1200
warning: 850
error: 1500

function_parameter_count:
Expand All @@ -72,11 +73,4 @@ type_name:
- iPhone
- API

identifier_name:
min_length: # only min_length
error: 1 # only error
# excluded: # excluded via string array
# - id
# - URL
# - GlobalAPIKey
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1410"
LastUpgradeVersion = "1610"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
46 changes: 41 additions & 5 deletions Core/Core.xcodeproj/project.pbxproj

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Core/Core.xcodeproj/xcshareddata/xcschemes/Core.xcscheme
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1430"
LastUpgradeVersion = "1610"
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
Expand Down
5 changes: 2 additions & 3 deletions Core/Core/Constants.swift → Core/Core/AuthConstants.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
//
// Constants.swift
// AuthConstants.swift
// Core
//
// Created by Vladimir Chekyrta on 14.09.2022.
//

import Foundation

// TODO move it to config file and parse
public struct Constants {
public struct AuthConstants {
public static let GrantTypePassword = "password"
public static let GrantTypeRefreshToken = "refresh_token"
}
2 changes: 1 addition & 1 deletion Core/Core/Configuration/Config/Config.swift
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ extension Config: ConfigProtocol {

// Mark - For testing and SwiftUI preview
#if DEBUG
public class ConfigMock: Config {
public class ConfigMock: Config, @unchecked Sendable {
private let config: [String: Any] = [
"API_HOST_URL": "https://www.example.com",
"SSO_URL": "https://www.example.com",
Expand Down
45 changes: 20 additions & 25 deletions Core/Core/Extensions/DateExtension.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public extension Date {
specificFormatter.dateFormat = isCurrentYear ? "MMMM d" : "MMMM d, yyyy"
return dueInString + specificFormatter.string(from: self)
}

func isDateInNextWeek(date: Date, currentDate: Date) -> Bool {
let calendar = Calendar.current
guard let nextWeek = calendar.date(byAdding: .weekOfYear, value: 1, to: currentDate) else { return false }
Expand All @@ -121,19 +121,19 @@ public extension Date {
}
self = date
}

init(milliseconds: Double) {
let now = Date()
let calendar = Calendar.current
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: now)
components.nanosecond = Int((milliseconds.truncatingRemainder(dividingBy: 1)) * 1000000)
let seconds = Int(milliseconds)
components.second = seconds % 60
components.minute = (seconds / 60) % 60
components.hour = (seconds / 3600) % 24
let date = calendar.date(from: components) ?? Date()
self = date
}
init(milliseconds: Double) {
let now = Date()
let calendar = Calendar.current
var components = calendar.dateComponents([.year, .month, .day, .hour, .minute, .second], from: now)
components.nanosecond = Int((milliseconds.truncatingRemainder(dividingBy: 1)) * 1000000)
let seconds = Int(milliseconds)
components.second = seconds % 60
components.minute = (seconds / 60) % 60
components.hour = (seconds / 3600) % 24
let date = calendar.date(from: components) ?? Date()
self = date
}
}

public enum DateStringStyle {
Expand All @@ -153,11 +153,11 @@ public extension Date {
func secondsSinceMidnight() -> Double {
let calendar = Calendar.current
let components = calendar.dateComponents([.hour, .minute, .second], from: self)

guard let hours = components.hour, let minutes = components.minute, let seconds = components.second else {
return 0.0
}

let totalSeconds = Double(hours) * 3600.0 + Double(minutes) * 60.0 + Double(seconds)
return totalSeconds
}
Expand Down Expand Up @@ -193,7 +193,7 @@ public extension Date {
}

let date = dateFormatter.string(from: self)

switch style {
case .courseStartsMonthDDYear:
return CoreLocalization.Date.courseStarts + " " + date
Expand Down Expand Up @@ -229,17 +229,12 @@ public extension Date {
case .shortWeekdayMonthDayYear:
return (
dueIn ? CoreLocalization.Date.dueIn : ""
) + getShortWeekdayMonthDayYear(dateFormatterString: date)
) + date
}
}

private func applyShortWeekdayMonthDayYear(dateFormatter: DateFormatter) {
dateFormatter.dateFormat = "MMMM d, yyyy"
}

private func getShortWeekdayMonthDayYear(dateFormatterString: String) -> String {
let days = Calendar.current.dateComponents([.day], from: self, to: Date())
return dateFormatterString
dateFormatter.dateFormat = "MMMM d, yyyy"
}

func isCurrentYear() -> Bool {
Expand All @@ -253,7 +248,7 @@ public extension Date {
func isEarlierThanOrEqualTo(date: Date) -> Bool {
timeIntervalSince1970 <= date.timeIntervalSince1970
}

func isLaterThanOrEqualTo(date: Date) -> Bool {
timeIntervalSince1970 >= date.timeIntervalSince1970
}
Expand Down
2 changes: 1 addition & 1 deletion Core/Core/Network/AuthEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ enum AuthEndpoint: EndPointType {
switch self {
case let .getAccessToken(username, password, clientId, tokenType):
let params: [String: Encodable & Sendable] = [
"grant_type": Constants.GrantTypePassword,
"grant_type": AuthConstants.GrantTypePassword,
"client_id": clientId,
"username": username,
"password": password,
Expand Down
77 changes: 0 additions & 77 deletions Core/Core/Network/DownloadManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ public class DownloadManager: DownloadManagerProtocol {
self.failedDownloads = []
}
}
print(">>> IS NIL")
return
}
if !connectivity.isInternetAvaliable {
Expand Down Expand Up @@ -824,79 +823,3 @@ public final class BackgroundTaskProvider: @unchecked Sendable {
}
}
}

// Mark - For testing and SwiftUI preview
#if DEBUG
public class DownloadManagerMock: DownloadManagerProtocol {

public init() {}

public func updateUnzippedFileSize(for sequentials: [CourseSequential]) -> [CourseSequential] {[]}

public var currentDownloadTask: DownloadDataTask? {
return nil
}

public func publisher() -> AnyPublisher<Int, Never> {
return Just(1).eraseToAnyPublisher()
}

public func eventPublisher() -> AnyPublisher<DownloadManagerEvent, Never> {
return Just(
.canceled(
.init(
id: "",
blockId: "",
courseId: "",
userId: 0,
url: "",
fileName: "",
displayName: "",
progress: 1,
resumeData: nil,
state: .inProgress,
type: .video,
fileSize: 0,
lastModified: ""
)
)
).eraseToAnyPublisher()
}

public func addToDownloadQueue(blocks: [CourseBlock]) {}

public func getDownloadTasks() -> [DownloadDataTask] {
[]
}

public func getDownloadTasksForCourse(_ courseId: String) async -> [DownloadDataTask] {
await withCheckedContinuation { continuation in
continuation.resume(returning: [])
}
}

public func cancelDownloading(courseId: String, blocks: [CourseBlock]) async throws {}

public func cancelDownloading(task: DownloadDataTask) {}

public func cancelDownloading(courseId: String) async {}

public func cancelAllDownloading() async throws {}

public func resumeDownloading() {}

public func deleteFile(blocks: [CourseBlock]) {}

public func deleteAllFiles() {}

public func fileUrl(for blockId: String) -> URL? {
return nil
}

public func isLargeVideosSize(blocks: [CourseBlock]) -> Bool {
false
}

public func removeAppSupportDirectoryUnusedContent() {}
}
#endif
85 changes: 85 additions & 0 deletions Core/Core/Network/DownloadManagerMock.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
//
// DownloadManagerMock.swift
// Core
//
// Created by Ivan Stepanok on 11.12.2024.
//

import Foundation
import Combine

// Mark - For testing and SwiftUI preview
#if DEBUG
public class DownloadManagerMock: DownloadManagerProtocol {

public init() {}

public func updateUnzippedFileSize(for sequentials: [CourseSequential]) -> [CourseSequential] {[]}

public var currentDownloadTask: DownloadDataTask? {
return nil
}

public func publisher() -> AnyPublisher<Int, Never> {
return Just(1).eraseToAnyPublisher()
}

public func eventPublisher() -> AnyPublisher<DownloadManagerEvent, Never> {
return Just(
.canceled(
.init(
id: "",
blockId: "",
courseId: "",
userId: 0,
url: "",
fileName: "",
displayName: "",
progress: 1,
resumeData: nil,
state: .inProgress,
type: .video,
fileSize: 0,
lastModified: ""
)
)
).eraseToAnyPublisher()
}

public func addToDownloadQueue(blocks: [CourseBlock]) {}

public func getDownloadTasks() -> [DownloadDataTask] {
[]
}

public func getDownloadTasksForCourse(_ courseId: String) async -> [DownloadDataTask] {
await withCheckedContinuation { continuation in
continuation.resume(returning: [])
}
}

public func cancelDownloading(courseId: String, blocks: [CourseBlock]) async throws {}

public func cancelDownloading(task: DownloadDataTask) {}

public func cancelDownloading(courseId: String) async {}

public func cancelAllDownloading() async throws {}

public func resumeDownloading() {}

public func deleteFile(blocks: [CourseBlock]) {}

public func deleteAllFiles() {}

public func fileUrl(for blockId: String) -> URL? {
return nil
}

public func isLargeVideosSize(blocks: [CourseBlock]) -> Bool {
false
}

public func removeAppSupportDirectoryUnusedContent() {}
}
#endif
2 changes: 1 addition & 1 deletion Core/Core/Network/RequestInterceptor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ final public class RequestInterceptor: Alamofire.RequestInterceptor {
let url = config.baseURL.appendingPathComponent("/oauth2/access_token")

let parameters: [String: Encodable & Sendable] = [
"grant_type": Constants.GrantTypeRefreshToken,
"grant_type": AuthConstants.GrantTypeRefreshToken,
"client_id": config.oAuthClientId,
"refresh_token": refreshToken,
"token_type": config.tokenType.rawValue,
Expand Down
Loading

0 comments on commit d489e1c

Please sign in to comment.