Skip to content

Commit

Permalink
Merge pull request #21 from sitomani/swiftlint-setup
Browse files Browse the repository at this point in the history
Set up SwiftLint for the project
  • Loading branch information
sitomani committed Oct 7, 2023
2 parents 3d4813a + 7e3e7a9 commit f3344cd
Show file tree
Hide file tree
Showing 72 changed files with 1,599 additions and 1,624 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,6 @@ Cartfile.resolved
.DS_Store
fastlane/report.xml
xcuserdata
xcshareddata
*.ipa
*.dSYM.zip
12 changes: 12 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
included: # paths to include during linting. `--path` is ignored if present.
- 4champ
- SamplePlayer
excluded: # paths to ignore during linting. Takes precedence over `included`.
disabled_rules:
- type_body_length
- file_length
- nesting
identifier_name:
min_length: 2
max_length: 40
line_length: 160
28 changes: 25 additions & 3 deletions 4champ.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
archiveVersion = 1;
classes = {
};
objectVersion = 52;
objectVersion = 54;
objects = {

/* Begin PBXBuildFile section */
Expand Down 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 Expand Up @@ -180,7 +180,7 @@
454F520F21610F83007011F3 /* ComposerCell.xib */ = {isa = PBXFileReference; lastKnownFileType = file.xib; path = ComposerCell.xib; sourceTree = "<group>"; };
455CC0A52104A0E20094A5D3 /* SwiftyBeaver.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SwiftyBeaver.framework; path = Carthage/Build/iOS/SwiftyBeaver.framework; sourceTree = "<group>"; };
4569AC8A21628C70000EDFDC /* UISearchBar+ActivityIndicator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UISearchBar+ActivityIndicator.swift"; sourceTree = "<group>"; };
456E6F2D240A5FAF0034BDA2 /* PlaylistView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaylistView.swift; sourceTree = "<group>"; };
456E6F2D240A5FAF0034BDA2 /* PlaylistView.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = PlaylistView.swift; sourceTree = "<group>"; tabWidth = 2; };
45855FC624444C9B0079C767 /* ampplayer.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = ampplayer.entitlements; sourceTree = "<group>"; };
45855FC8244467420079C767 /* DownloadView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DownloadView.swift; sourceTree = "<group>"; };
45855FCA244475050079C767 /* DownloadHostingController.swift */ = {isa = PBXFileReference; indentWidth = 2; lastKnownFileType = sourcecode.swift; path = DownloadHostingController.swift; sourceTree = "<group>"; tabWidth = 2; };
Expand Down Expand Up @@ -543,6 +543,7 @@
isa = PBXNativeTarget;
buildConfigurationList = 45D392B520B1DDEE00EEF4E3 /* Build configuration list for PBXNativeTarget "ampplayer" */;
buildPhases = (
73CD16E12AD16C3400987AD6 /* ShellScript */,
45D3929D20B1DDEC00EEF4E3 /* Sources */,
45D3929E20B1DDEC00EEF4E3 /* Frameworks */,
45D3929F20B1DDEC00EEF4E3 /* Resources */,
Expand Down Expand Up @@ -631,6 +632,27 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
73CD16E12AD16C3400987AD6 /* ShellScript */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "export PATH=\"$PATH:/opt/homebrew/bin\"\n\nif which swiftlint; then\n swiftlint —-fix --format\n swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
45D3929D20B1DDEC00EEF4E3 /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
67 changes: 31 additions & 36 deletions 4champ/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ let shareUtil = ShareUtility()

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

private var _bgFetchCallback: ((UIBackgroundFetchResult) -> Void)?

private var sharedMod: MMD?

private lazy var dlController: DownloadController = DownloadController()

var window: UIWindow?

func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
// Override point for customization after application launch.
Appearance.setup()
Expand All @@ -39,7 +39,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
// UNCOMMENT BELOW TWO LINES TO TEST LOCAL NOTIFICATIONS
// settings.prevCollectionSize = 0
// settings.newestPlayed = 152890

updateLatest()
UIApplication.shared.beginReceivingRemoteControlEvents()

Expand All @@ -50,7 +50,7 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
application.setMinimumBackgroundFetchInterval(UIApplication.backgroundFetchIntervalMinimum)
return true
}

func setupAVSession() {
let sess = AVAudioSession.sharedInstance()
do {
Expand All @@ -60,65 +60,62 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
log.error(error)
}
}

func applicationWillResignActive(_ application: UIApplication) {
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
// Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
}

func applicationDidEnterBackground(_ application: UIApplication) {
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
}

func applicationWillEnterForeground(_ application: UIApplication) {
}

func applicationDidBecomeActive(_ application: UIApplication) {
}

func applicationWillTerminate(_ application: UIApplication) {
modulePlayer.cleanup()
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
}

func application(_ application: UIApplication, performFetchWithCompletionHandler completionHandler: @escaping (UIBackgroundFetchResult) -> Void) {
log.debug("performFetch")
_bgFetchCallback = completionHandler
updateLatest()
}

func application(_ application: UIApplication, continue userActivity: NSUserActivity, restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {


func application(_ application: UIApplication,
continue userActivity: NSUserActivity,
restorationHandler: @escaping ([UIUserActivityRestoring]?) -> Void) -> Bool {

guard userActivity.activityType == NSUserActivityTypeBrowsingWeb,
let url = userActivity.webpageURL,
let components = URLComponents(url: url, resolvingAgainstBaseURL: true) else {
return false
}

if components.path == "/mod", let idString = components.queryItems?.first?.value, let modId = Int(idString) {
dlController.rootViewController = UIApplication.shared.windows[0].rootViewController
dlController.show(modId: modId)
}

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
}

func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
return true
}

/// Set up SwiftyBeaver logging
func setupLogging() {
let console = ConsoleDestination() // log to Xcode Console
Expand All @@ -130,14 +127,14 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
console.levelString.debug = "◾️"
console.levelString.verbose = "◽️"
log.addDestination(console)

console.minLevel = .warning
#if DEBUG
console.minLevel = .debug
#endif
log.info("Logger initialized")
}

func cleanupFiles() {
let fileManager = FileManager.default
let documentsURL = fileManager.urls(for: .documentDirectory, in: .userDomainMask)[0]
Expand All @@ -151,13 +148,13 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
log.error("Error while enumerating files \(documentsURL.path): \(error.localizedDescription)")
}
}

func updateLatest() {
log.debug("")
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 All @@ -167,12 +164,12 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
}
}
}

func updateCollectionSize(size: Int) {
log.debug("")
settings.collectionSize = size
let prevSize = settings.prevCollectionSize

// Only fire the request once per a given collectionSize/diff
if prevSize < size && settings.badgeCount < Constants.maxBadgeValue {
let fmt = "Radio_Notification".l13n()
Expand All @@ -190,5 +187,3 @@ class AppDelegate: UIResponder, UIApplicationDelegate {
_bgFetchCallback = nil
}
}


3 changes: 1 addition & 2 deletions 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 All @@ -34,7 +33,7 @@ extension ModuleInfo: Identifiable {
@NSManaged public var playlists: NSSet?
@NSManaged public var serviceId: NSNumber?
@NSManaged public var serviceKey: String?

public var id: Int {
return modId?.intValue ?? 0
}
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>"
}
}

3 changes: 1 addition & 2 deletions 4champ/Data/Playlist+CoreDataProperties.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,12 @@
import Foundation
import CoreData


extension Playlist: Identifiable {

@nonobjc public class func fetchRequest() -> NSFetchRequest<Playlist> {
return NSFetchRequest<Playlist>(entityName: "Playlist")
}

@NSManaged public var locked: NSNumber?
@NSManaged public var playhead: NSNumber?
@NSManaged public var playmode: NSNumber?
Expand Down
22 changes: 10 additions & 12 deletions 4champ/Data/Structs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@ struct Notifications {
struct MMD: Identifiable {
init() {
}

static let supportedTypes: [String] = Replay.supportedFormats

init(cdi: ModuleInfo) {
self.init()
self.composer = cdi.modAuthor
Expand All @@ -51,7 +51,7 @@ struct MMD: Identifiable {
self.serviceKey = cdi.serviceKey
self.favorite = cdi.modFavorite?.boolValue ?? false
}

init(path: String, modId: Int) {
self.init()
downloadPath = URL.init(string: path)
Expand All @@ -63,13 +63,13 @@ 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!)
}
}
}

var id: Int?
var name: String?
var type: String?
Expand All @@ -87,22 +87,22 @@ struct MMD: Identifiable {
}
return false
}

func hasBeenSaved() -> Bool {
guard let modId = self.id else {
return false
}
let saved = moduleStorage.getModuleById(modId)
return saved != nil
}

func queueIndex() -> Int? {
if let queueIndex = modulePlayer.playQueue.firstIndex(of: self) {
return queueIndex
}
return nil
}

func supported() -> Bool {
if MMD.supportedTypes.contains(self.type ?? "") && (self.note?.count ?? 0) == 0 {
return true
Expand All @@ -112,9 +112,7 @@ struct MMD: Identifiable {
}

extension MMD: Equatable {}
func ==(lhs: MMD, rhs: MMD) -> Bool {
func == (lhs: MMD, rhs: MMD) -> Bool {
let eq = lhs.id == rhs.id && lhs.id != nil
return eq
}


0 comments on commit f3344cd

Please sign in to comment.