Skip to content

Commit

Permalink
Added swiftlint config + run autocorrect
Browse files Browse the repository at this point in the history
  • Loading branch information
sitomani committed Oct 7, 2023
1 parent ba3aeed commit 55fbfe9
Show file tree
Hide file tree
Showing 64 changed files with 377 additions and 521 deletions.
14 changes: 14 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
included: # paths to include during linting. `--path` is ignored if present.
- 4champ
excluded: # paths to ignore during linting. Takes precedence over `included`.
disabled_rules:
- trailing_whitespace
- line_length
- type_body_length
- file_length
- function_body_length
- nesting
identifier_name:
min_length: 2
max_length: 40
line_length: 160
2 changes: 1 addition & 1 deletion 4champ.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
450E506021879347008FB155 /* SettingsRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsRouter.swift; sourceTree = "<group>"; };
450E506121879347008FB155 /* SettingsModels.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = SettingsModels.swift; sourceTree = "<group>"; tabWidth = 2; };
450E506221879347008FB155 /* SettingsViewController.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = SettingsViewController.swift; sourceTree = "<group>"; tabWidth = 2; };
450E506321879347008FB155 /* SettingsInteractor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsInteractor.swift; sourceTree = "<group>"; };
450E506321879347008FB155 /* SettingsInteractor.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = SettingsInteractor.swift; sourceTree = "<group>"; tabWidth = 2; };
450E506C2187A066008FB155 /* SettingsStereoCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsStereoCell.swift; sourceTree = "<group>"; };
451B6A9A2204B6CC001848FA /* LocalPresenter.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = LocalPresenter.swift; sourceTree = "<group>"; tabWidth = 2; };
451B6A9C2204B6CC001848FA /* LocalRouter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalRouter.swift; sourceTree = "<group>"; };
Expand Down
8 changes: 3 additions & 5 deletions 4champ/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
return true
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey: Any] = [:]) -> Bool {
if url.scheme == "fourchamp" && url.host == "modules" {
if let idString = url.path.split(separator: "/").first, let modId = Int(idString) {
dlController.show(modId: modId)
}
} else {
dlController.showImport(for: [url]);
dlController.showImport(for: [url])
}
return true
}
Expand Down Expand Up @@ -157,7 +157,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
let req = RESTRoutes.latestId
AF.request(req).validate().responseString { resp in
switch resp.result {
case .failure(_):
case .failure:
self._bgFetchCallback?(.noData)
self._bgFetchCallback = nil
case .success(let str):
Expand Down Expand Up @@ -190,5 +190,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
_bgFetchCallback = nil
}
}


1 change: 0 additions & 1 deletion 4champ/Data/ModuleInfo+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation
import CoreData


extension ModuleInfo: Identifiable {

@nonobjc public class func fetchRequest() -> NSFetchRequest<ModuleInfo> {
Expand Down
1 change: 0 additions & 1 deletion 4champ/Data/Playlist+CoreDataClass.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,3 @@ public class Playlist: NSManagedObject {
return self.plName ?? "<no name>"
}
}

1 change: 0 additions & 1 deletion 4champ/Data/Playlist+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import Foundation
import CoreData


extension Playlist: Identifiable {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Playlist> {
Expand Down
6 changes: 2 additions & 4 deletions 4champ/Data/Structs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ struct MMD: Identifiable {
if let modNameParts = components.last?.components(separatedBy: ".") {
type = modNameParts.first ?? "MOD"
name = modNameParts[1...modNameParts.count - 2].joined(separator: ".")
name = name?.replacingOccurrences(of: "%", with: "%25") //replace percent signs with encoding
name = name?.removingPercentEncoding //before removing the encoding
name = name?.replacingOccurrences(of: "%", with: "%25") // replace percent signs with encoding
name = name?.removingPercentEncoding // before removing the encoding
localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(name!).appendingPathExtension(type!)
}
}
Expand Down Expand Up @@ -116,5 +116,3 @@ func ==(lhs: MMD, rhs: MMD) -> Bool {
let eq = lhs.id == rhs.id && lhs.id != nil
return eq
}


4 changes: 2 additions & 2 deletions 4champ/Networking/ModuleFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ enum FetcherState {
case done(mmd: MMD)
}

enum FetcherError:Error {
enum FetcherError: Error {
case unsupportedFormat
}

Expand Down Expand Up @@ -131,7 +131,7 @@ class ModuleFetcher {
return
}
do {
//store to file and make sure it's not writing over an existing mod
// store to file and make sure it's not writing over an existing mod
var numberExt = 0
var localPath = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).last!.appendingPathComponent(mmd.name!).appendingPathExtension(mmd.type!)
while FileManager.default.fileExists(atPath: localPath.path) {
Expand Down
6 changes: 3 additions & 3 deletions 4champ/Networking/RESTRoutes.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ enum SearchType: String {
Enumeration for the available endpoints at 4champ backend
*/
enum RESTRoutes: URLRequestConvertible {
//Router paths
// Router paths
case latestId
case modulePath(id: Int)
case search(type: SearchType, text: String, position: Int)
Expand All @@ -54,15 +54,15 @@ enum RESTRoutes: URLRequestConvertible {
case .modulePath(let id):
return("/get_module?id=\(id)", nil)
case .search(let type, let text, let position):
return("/search_\(type.rawValue)?", ["t": text, "s":position, "e": position + pageSize-1])
return("/search_\(type.rawValue)?", ["t": text, "s": position, "e": position + pageSize-1])
case .listComposers(let groupId):
return("list_composers", ["t": groupId])
case .listModules(let composerId):
return("list_modules", ["t": composerId])
}
}

//URLRequestConvertible protocol implementation
// URLRequestConvertible protocol implementation
func asURLRequest() throws -> URLRequest {
guard let url = URL.init(string: self.route.path, relativeTo: URL.init(string: "https://4champ.net")) else {
// guard let url = URL.init(string: self.route.path, relativeTo: URL.init(string: "http:https://localhost:8081")) else {
Expand Down
15 changes: 7 additions & 8 deletions 4champ/Replay/ModulePlayer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ enum PlayerError: Error {
}

/// possible states of a ModulePlayer
enum PlayerStatus:Int {
enum PlayerStatus: Int {
case initialised
case stopped
case playing
Expand Down Expand Up @@ -56,7 +56,7 @@ protocol ModulePlayerObserver: class {
func errorOccurred(error: PlayerError)

/// called when play queue changes (e.g. due to playlist change, or when modules are added to queue by user)
func queueChanged(changeType:QueueChange)
func queueChanged(changeType: QueueChange)
}

class ModulePlayer: NSObject {
Expand All @@ -74,7 +74,7 @@ class ModulePlayer: NSObject {
let songName = mod.name!
let playlistName = "LockScreen_Radio".l13n()

let artwork = MPMediaItemArtwork.init(boundsSize: mpImage.size, requestHandler: { (size) -> UIImage in
let artwork = MPMediaItemArtwork.init(boundsSize: mpImage.size, requestHandler: { (_) -> UIImage in
return self.mpImage
})

Expand Down Expand Up @@ -106,7 +106,7 @@ class ModulePlayer: NSObject {

override init() {
super.init()
moduleStorage.addStorageObserver(self) //listen to metadata changes
moduleStorage.addStorageObserver(self) // listen to metadata changes

renderer.initAudio()
renderer.streamDelegate = self
Expand Down Expand Up @@ -172,7 +172,7 @@ class ModulePlayer: NSObject {
}
renderer.stop()
let mod = playQueue[at]
if renderer.loadModule(path, type:mod.type) {
if renderer.loadModule(path, type: mod.type) {
let settings = SettingsInteractor()
setStereoSeparation(settings.stereoSeparation)
setInterpolation(settings.interpolation)
Expand Down Expand Up @@ -237,7 +237,7 @@ class ModulePlayer: NSObject {
func playPrev() {
guard !radioOn else {
radioRemoteControl?.playPrev()
return;
return
}
guard let current = currentModule, playQueue.count > 0 else {
return
Expand Down Expand Up @@ -290,14 +290,13 @@ class ModulePlayer: NSObject {
playQueue.removeAll()
currentModule = nil
}


/// Handle audio route change notifications
@objc func handleRouteChange(notification: Notification) {
log.debug("")
guard let userInfo = notification.userInfo,
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
let reason = AVAudioSession.RouteChangeReason(rawValue:reasonValue) else {
let reason = AVAudioSession.RouteChangeReason(rawValue: reasonValue) else {
return
}

Expand Down
1 change: 0 additions & 1 deletion 4champ/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,4 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// (UIApplication.shared.delegate as? AppDelegate)?.saveContext()
}


}
7 changes: 3 additions & 4 deletions 4champ/Scenes/About/AboutHeaderView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ extension UIColor {
}
}


extension UIImage {
func resizeImageWith(newSize: CGSize) -> UIImage {
let horizontalRatio = newSize.width / size.width
Expand All @@ -50,7 +49,7 @@ class AboutHeaderView: UIButton {
setTitle(" \(titleKey.l13n())", for: .normal)
imageView?.contentMode = .scaleAspectFit
backgroundColor = Appearance.ampLightBlueColor
tintColor = UIColor.init(rgb: 0xc6c6c6);
tintColor = UIColor.init(rgb: 0xc6c6c6)
if let image = UIImage.init(named: imageKey) {

if titleKey == "Twitter" {
Expand All @@ -65,9 +64,9 @@ class AboutHeaderView: UIButton {
lbl.text = "©"
lbl.font = UIFont.systemFont(ofSize: 29.0)
lbl.textColor = UIColor.init(rgb: 0xc6c6c6)
UIGraphicsBeginImageContext(lbl.bounds.size);
UIGraphicsBeginImageContext(lbl.bounds.size)
lbl.layer.render(in: UIGraphicsGetCurrentContext()!)
let renderedImg = UIGraphicsGetImageFromCurrentImageContext();
let renderedImg = UIGraphicsGetImageFromCurrentImageContext()
setImage(renderedImg, for: .normal)
}
}
Expand Down
27 changes: 12 additions & 15 deletions 4champ/Scenes/About/AboutInteractor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,31 @@ import UIKit

struct AppInfo {

var appName : String {
var appName: String {
return readFromInfoPlist(withKey: "CFBundleName") ?? "(unknown app name)"
}

var version : String {
var version: String {
return readFromInfoPlist(withKey: "CFBundleShortVersionString") ?? "(unknown app version)"
}

var build : String {
var build: String {
return readFromInfoPlist(withKey: "CFBundleVersion") ?? "(unknown build number)"
}

var minimumOSVersion : String {
var minimumOSVersion: String {
return readFromInfoPlist(withKey: "MinimumOSVersion") ?? "(unknown minimum OSVersion)"
}

var copyrightNotice : String {
var copyrightNotice: String {
return readFromInfoPlist(withKey: "NSHumanReadableCopyright") ?? "(unknown copyright notice)"
}

var bundleIdentifier : String {
var bundleIdentifier: String {
return readFromInfoPlist(withKey: "CFBundleIdentifier") ?? "(unknown bundle identifier)"
}

var developer : String { return "my awesome name" }
var developer: String { return "my awesome name" }

// lets hold a reference to the Info.plist of the app as Dictionary
private let infoPlistDictionary = Bundle.main.infoDictionary
Expand All @@ -44,27 +44,24 @@ struct AppInfo {
}
}

protocol AboutBusinessLogic
{
protocol AboutBusinessLogic {
var details: About.Details { get }
}

protocol AboutDataStore
{
protocol AboutDataStore {
var details: About.Details { get }
}

class AboutInteractor: AboutBusinessLogic, AboutDataStore
{
class AboutInteractor: AboutBusinessLogic, AboutDataStore {
var presenter: AboutPresentationLogic?

var details: About.Details

init() {
log.debug("")
let aboutTitle = "4champ \(AppInfo().version) (\(AppInfo().build))"
let titleKeys = [aboutTitle, "Twitter","About_Copyrights", "TabBar_Local", "TabBar_Playlist", "TabBar_Search", "TabBar_Radio", "About_Licenses"]
let contentKeys = ["AboutView_Info", "AboutView_Twitter", "AboutView_Legal", "AboutView_Local","AboutView_Playlists", "AboutView_Search", "AboutView_Radio"]
let titleKeys = [aboutTitle, "Twitter", "About_Copyrights", "TabBar_Local", "TabBar_Playlist", "TabBar_Search", "TabBar_Radio", "About_Licenses"]
let contentKeys = ["AboutView_Info", "AboutView_Twitter", "AboutView_Legal", "AboutView_Local", "AboutView_Playlists", "AboutView_Search", "AboutView_Radio"]
let imageKeys = ["about", "twitter_small", "legal", "localMods", "playlist", "search", "radio", "about"]
let lics = ["Alamofire", "GzipSwift", "HivelyTracker", "LibOpenMPT", "UADE"]
let licUrls = ["https://github.com/Alamofire/Alamofire/blob/master/LICENSE",
Expand Down
25 changes: 10 additions & 15 deletions 4champ/Scenes/About/AboutModels.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,28 +7,23 @@

import UIKit

enum About
{
enum About {
struct Details {
var titles:[String]
var contents:[String]
var images:[String]
var licenseLinks:[String]
var licenseNames:[String]
var titles: [String]
var contents: [String]
var images: [String]
var licenseLinks: [String]
var licenseNames: [String]
}
// MARK: Use cases

enum Status
{
struct Request
{
enum Status {
struct Request {
}
struct Response
{
struct Response {
var isPlaying: Bool = false
}
struct ViewModel
{
struct ViewModel {
var isPlaying: Bool = false
}
}
Expand Down
6 changes: 2 additions & 4 deletions 4champ/Scenes/About/AboutPresenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@

import UIKit

protocol AboutPresentationLogic
{
protocol AboutPresentationLogic {
func presentStatus(_ status: About.Status.Response)
}

class AboutPresenter: AboutPresentationLogic
{
class AboutPresenter: AboutPresentationLogic {
weak var viewController: AboutDisplayLogic?

// MARK: Do something
Expand Down
11 changes: 4 additions & 7 deletions 4champ/Scenes/About/AboutRouter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,15 @@

import UIKit

@objc protocol AboutRoutingLogic
{
//func routeToSomewhere(segue: UIStoryboardSegue?)
@objc protocol AboutRoutingLogic {
// func routeToSomewhere(segue: UIStoryboardSegue?)
}

protocol AboutDataPassing
{
protocol AboutDataPassing {
var dataStore: AboutDataStore? { get }
}

class AboutRouter: NSObject, AboutRoutingLogic, AboutDataPassing
{
class AboutRouter: NSObject, AboutRoutingLogic, AboutDataPassing {
weak var viewController: AboutViewController?
var dataStore: AboutDataStore?
}
Loading

0 comments on commit 55fbfe9

Please sign in to comment.