diff --git a/.swiftlint.yml b/.swiftlint.yml index dcd9ed1..1efd31d 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -11,8 +11,8 @@ opt_in_rules: # some rules are only opt-in - empty_count # included: # paths to include during linting. `--path` is ignored if present. # - Clocker -# excluded: # paths to ignore during linting. Takes precedence over `included`. - # - Carthage +excluded: # paths to ignore during linting. Takes precedence over `included`. + - Clocker/Dependencies # - Pods # - Source/ExcludedFolder # - Source/ExcludedFile.swift diff --git a/Clocker/AppDelegate.swift b/Clocker/AppDelegate.swift index 2203052..664f58a 100644 --- a/Clocker/AppDelegate.swift +++ b/Clocker/AppDelegate.swift @@ -96,8 +96,8 @@ open class AppDelegate : NSObject, NSApplicationDelegate { } private lazy var controller: OnboardingController? = { - let s = NSStoryboard(name: NSStoryboard.Name("Onboarding"), bundle: nil) - return s.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("onboardingFlow")) as? OnboardingController + let onboardingStoryboard = NSStoryboard(name: NSStoryboard.Name("Onboarding"), bundle: nil) + return onboardingStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("onboardingFlow")) as? OnboardingController }() private func showOnboardingFlow() { diff --git a/Clocker/Clocker/LocationController.swift b/Clocker/Clocker/LocationController.swift index 272b598..cd78d6b 100644 --- a/Clocker/Clocker/LocationController.swift +++ b/Clocker/Clocker/LocationController.swift @@ -7,9 +7,9 @@ class LocationController: NSObject { public static let sharedInstance = LocationController() private var locationManager: CLLocationManager = { - let l = CLLocationManager() - l.desiredAccuracy = kCLLocationAccuracyThreeKilometers - return l + let locationManager = CLLocationManager() + locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers + return locationManager }() @objc class func sharedController() -> LocationController { diff --git a/Clocker/ClockerUITests/FloatingWindowTests.swift b/Clocker/ClockerUITests/FloatingWindowTests.swift index a84e54a..16f2332 100644 --- a/Clocker/ClockerUITests/FloatingWindowTests.swift +++ b/Clocker/ClockerUITests/FloatingWindowTests.swift @@ -114,11 +114,9 @@ class FloatingWindowTests: XCTestCase { let menubarDisplayQuery = app.tables.checkBoxes.matching(NSPredicate(format: "value == 1", "")) let menubarDisplayQueryCount = menubarDisplayQuery.count - for i in 0.. Date { + static func + (leftAddend: Date, rightAddend: TimeChunk) -> Date { return leftAddend.add(rightAddend) } /** * Operator overload for subtracting a `TimeChunk` from a date. */ - static func -(minuend: Date, subtrahend: TimeChunk) -> Date { + static func - (minuend: Date, subtrahend: TimeChunk) -> Date { return minuend.subtract(subtrahend) } /** * Operator overload for adding a `TimeInterval` to a date. */ - static func +(leftAddend: Date, rightAddend: Int) -> Date { + static func + (leftAddend: Date, rightAddend: Int) -> Date { return leftAddend.addingTimeInterval((TimeInterval(rightAddend))) } /** * Operator overload for subtracting a `TimeInterval` from a date. */ - static func -(minuend: Date, subtrahend: Int) -> Date { + static func - (minuend: Date, subtrahend: Int) -> Date { return minuend.addingTimeInterval(-(TimeInterval(subtrahend))) } diff --git a/Clocker/Dependencies/Date Additions/TimeChunk.swift b/Clocker/Dependencies/Date Additions/TimeChunk.swift index 76f4377..6decb02 100755 --- a/Clocker/Dependencies/Date Additions/TimeChunk.swift +++ b/Clocker/Dependencies/Date Additions/TimeChunk.swift @@ -242,28 +242,28 @@ public struct TimeChunk { /** * Operator overload for adding two `TimeChunk`s */ - public static func +(leftAddend: TimeChunk, rightAddend: TimeChunk) -> TimeChunk { + public static func + (leftAddend: TimeChunk, rightAddend: TimeChunk) -> TimeChunk { return leftAddend.lengthened(by: rightAddend) } /** * Operator overload for subtracting two `TimeChunk`s */ - public static func -(minuend: TimeChunk, subtrahend: TimeChunk) -> TimeChunk { + public static func - (minuend: TimeChunk, subtrahend: TimeChunk) -> TimeChunk { return minuend.shortened(by: subtrahend) } /** * Operator overload for checking if two `TimeChunk`s are equal */ - public static func ==(left: TimeChunk, right: TimeChunk) -> Bool { + public static func == (left: TimeChunk, right: TimeChunk) -> Bool { return left.equals(chunk: right) } /** * Operator overload for inverting (negating all variables) a `TimeChunk` */ - public static prefix func -(chunk: TimeChunk) -> TimeChunk { + public static prefix func - (chunk: TimeChunk) -> TimeChunk { var invertedChunk = chunk invertedChunk.seconds = -chunk.seconds invertedChunk.minutes = -chunk.minutes diff --git a/Clocker/Dependencies/Solar.swift b/Clocker/Dependencies/Solar.swift index 1897c23..e8d9af5 100644 --- a/Clocker/Dependencies/Solar.swift +++ b/Clocker/Dependencies/Solar.swift @@ -98,12 +98,12 @@ public struct Solar { rightAscenscion = normalise(rightAscenscion, withMaximum: 360) // Right ascension value needs to be in the same quadrant as L... - let Lquadrant = floor(longitude / 90) * 90 - let RAquadrant = floor(rightAscenscion / 90) * 90 - rightAscenscion = rightAscenscion + (Lquadrant - RAquadrant) + let leftQuadrant = floor(longitude / 90) * 90 + let rightQuadrant = floor(rightAscenscion / 90) * 90 + rightAscenscion += (leftQuadrant - rightQuadrant) // Convert RA into hours - rightAscenscion = rightAscenscion / 15 + rightAscenscion /= 15 // Calculate Sun's declination let sinDec = 0.39782 * sin(longitude.degreesToRadians) diff --git a/Clocker/Events and Reminders/CalendarHandler.swift b/Clocker/Events and Reminders/CalendarHandler.swift index 2ddb463..29b5209 100644 --- a/Clocker/Events and Reminders/CalendarHandler.swift +++ b/Clocker/Events and Reminders/CalendarHandler.swift @@ -257,8 +257,8 @@ extension EventCenter { // We now sort the array so that AllDay Events are first, then sort by startTime for date in eventsForDateMapper.keys { - let sortedEvents = eventsForDateMapper[date]?.sorted(by: { (e1, e2) -> Bool in - if e1.isAllDay { return true } else if e2.isAllDay { return false } else { return e1.event.startDate < e2.event.startDate } + let sortedEvents = eventsForDateMapper[date]?.sorted(by: { (event1, event2) -> Bool in + if event1.isAllDay { return true } else if event2.isAllDay { return false } else { return event1.event.startDate < event2.event.startDate } }) eventsForDateMapper[date] = sortedEvents } diff --git a/Clocker/Menu Bar/StatusItemHandler.swift b/Clocker/Menu Bar/StatusItemHandler.swift index 7af9207..fb6bb8c 100644 --- a/Clocker/Menu Bar/StatusItemHandler.swift +++ b/Clocker/Menu Bar/StatusItemHandler.swift @@ -15,9 +15,9 @@ class StatusItemHandler: NSObject { var menubarTimer: Timer? var statusItem: NSStatusItem = { - let s = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) - s.highlightMode = false - return s + let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) + statusItem.highlightMode = false + return statusItem }() private var menubarTitleHandler = MenubarHandler() diff --git a/Clocker/Menu Bar/StatusItemView.swift b/Clocker/Menu Bar/StatusItemView.swift index 7267268..7cd910c 100644 --- a/Clocker/Menu Bar/StatusItemView.swift +++ b/Clocker/Menu Bar/StatusItemView.swift @@ -3,10 +3,10 @@ import Cocoa private var defaultParagraphStyle: NSMutableParagraphStyle { - let p = NSMutableParagraphStyle() - p.alignment = .center - p.lineBreakMode = .byTruncatingTail - return p + let paragraphStyle = NSMutableParagraphStyle() + paragraphStyle.alignment = .center + paragraphStyle.lineBreakMode = .byTruncatingTail + return paragraphStyle } var compactModeTimeFont: NSFont { diff --git a/Clocker/Onboarding/OnboardingParentViewController.swift b/Clocker/Onboarding/OnboardingParentViewController.swift index 326efc7..9144335 100644 --- a/Clocker/Onboarding/OnboardingParentViewController.swift +++ b/Clocker/Onboarding/OnboardingParentViewController.swift @@ -177,9 +177,9 @@ class OnboardingParentViewController: NSViewController { } } - private func addChildIfNeccessary(_ vc: NSViewController) { - if children.contains(vc) == false { - addChild(vc) + private func addChildIfNeccessary(_ viewController: NSViewController) { + if children.contains(viewController) == false { + addChild(viewController) } } diff --git a/Clocker/Overall App/DataStore.swift b/Clocker/Overall App/DataStore.swift index 064585c..096d66c 100644 --- a/Clocker/Overall App/DataStore.swift +++ b/Clocker/Overall App/DataStore.swift @@ -80,7 +80,7 @@ class DataStore: NSObject { userDefaults.set(currentLineup, forKey: CLDefaultPreferenceKey) } - + private func shouldDisplayHelper(_ key: String) -> Bool { guard let value = retrieve(key: key) as? NSNumber else { return false diff --git a/Clocker/Panel/Data Layer/TimezoneData.swift b/Clocker/Panel/Data Layer/TimezoneData.swift index 86a27a8..7175d42 100644 --- a/Clocker/Panel/Data Layer/TimezoneData.swift +++ b/Clocker/Panel/Data Layer/TimezoneData.swift @@ -424,7 +424,7 @@ class TimezoneData: NSObject, NSCoding { static func == (lhs: TimezoneData, rhs: TimezoneData) -> Bool { return lhs.placeID == rhs.placeID } - + override func isEqual(to object: Any?) -> Bool { if let other = object as? TimezoneData { return placeID == other.placeID diff --git a/Clocker/Panel/Notes Popover/NotesPopover.swift b/Clocker/Panel/Notes Popover/NotesPopover.swift index bf215fd..f706dbb 100644 --- a/Clocker/Panel/Notes Popover/NotesPopover.swift +++ b/Clocker/Panel/Notes Popover/NotesPopover.swift @@ -292,7 +292,7 @@ class NotesPopover: NSViewController { let menubarIndex = timezones.firstIndex { (menubarLocation) -> Bool in if let convertedObject = TimezoneData.customObject(from: menubarLocation) { - return convertedObject == dataObject + return convertedObject.isEqual(dataObject) } return false @@ -320,7 +320,7 @@ class NotesPopover: NSViewController { } } - for timezoneObject in timezoneObjects where timezoneObject == dataObject { + for timezoneObject in timezoneObjects where timezoneObject.isEqual(dataObject) { overrideType == .timezoneFormat ? timezoneObject.setShouldOverrideGlobalTimeFormat(override) : timezoneObject.setShouldOverrideSecondsFormat(override) @@ -349,7 +349,7 @@ class NotesPopover: NSViewController { } } - for timezoneObject in timezoneObjects where timezoneObject == dataObject { + for timezoneObject in timezoneObjects where timezoneObject.isEqual(dataObject) { overrideType == .timezoneFormat ? timezoneObject.setShouldOverrideGlobalTimeFormat(override) : timezoneObject.setShouldOverrideSecondsFormat(override) diff --git a/Clocker/Panel/PanelController.swift b/Clocker/Panel/PanelController.swift index 2a78f3e..860f22b 100644 --- a/Clocker/Panel/PanelController.swift +++ b/Clocker/Panel/PanelController.swift @@ -46,16 +46,16 @@ class PanelController: ParentPanelController { func setFrameTheNewWay(_ rect: NSRect, _ maxX: CGFloat) { // Calculate window's top left point. // First, center window under status item. - let w = (window?.frame)!.width - var x = CGFloat(roundf(Float(rect.midX - w / 2))) - let y = CGFloat(rect.minY - 2) + let width = (window?.frame)!.width + var xPoint = CGFloat(roundf(Float(rect.midX - width / 2))) + let yPoint = CGFloat(rect.minY - 2) let kMinimumSpaceBetweenWindowAndScreenEdge: CGFloat = 10 - if x + w + kMinimumSpaceBetweenWindowAndScreenEdge > maxX { - x = maxX - w - kMinimumSpaceBetweenWindowAndScreenEdge + if xPoint + width + kMinimumSpaceBetweenWindowAndScreenEdge > maxX { + xPoint = maxX - width - kMinimumSpaceBetweenWindowAndScreenEdge } - window?.setFrameTopLeftPoint(NSPoint(x: x, y: y)) + window?.setFrameTopLeftPoint(NSPoint(x: xPoint, y: yPoint)) window?.invalidateShadow() } diff --git a/Clocker/Panel/ParentPanelController.swift b/Clocker/Panel/ParentPanelController.swift index 096e2c6..81271c7 100644 --- a/Clocker/Panel/ParentPanelController.swift +++ b/Clocker/Panel/ParentPanelController.swift @@ -367,7 +367,7 @@ class ParentPanelController: NSWindowController { // Set it to 95 expicity in case the row height is calculated be higher. height = 95.0 - if let note = currentObject?.note, note.count <= 0 { + if let note = currentObject?.note, note.isEmpty { height -= 30.0 } } diff --git a/Clocker/Panel/UI/CustomSliderCell.swift b/Clocker/Panel/UI/CustomSliderCell.swift index fb02bac..fad7306 100644 --- a/Clocker/Panel/UI/CustomSliderCell.swift +++ b/Clocker/Panel/UI/CustomSliderCell.swift @@ -20,12 +20,12 @@ class CustomSliderCell: NSSliderCell { var leftRect = rect leftRect.size.width = finalWidth - let bg = NSBezierPath(roundedRect: rect, + let background = NSBezierPath(roundedRect: rect, xRadius: barRadius, yRadius: barRadius) NSColor(calibratedRed: 67.0 / 255.0, green: 138.0 / 255.0, blue: 250.0 / 255.0, alpha: 1.0).setFill() - bg.fill() + background.fill() // Right Part diff --git a/Clocker/Panel/UI/NoTimezoneView.swift b/Clocker/Panel/UI/NoTimezoneView.swift index 9bcc126..92c0bb4 100644 --- a/Clocker/Panel/UI/NoTimezoneView.swift +++ b/Clocker/Panel/UI/NoTimezoneView.swift @@ -5,40 +5,40 @@ import QuartzCore class NoTimezoneView: NSView { private lazy var emoji: NSTextField = { - let l = NSTextField(frame: NSRect(x: frame.size.width / 2 - 50, + let emoji = NSTextField(frame: NSRect(x: frame.size.width / 2 - 50, y: frame.size.height / 2 - 50, width: 100, height: 100)) - l.wantsLayer = true - l.stringValue = "🌏" - l.isBordered = false - l.isEditable = false - l.focusRingType = .none - l.alignment = .center - l.font = NSFont.systemFont(ofSize: 80) - l.backgroundColor = .clear - l.setAccessibilityIdentifier("NoTimezoneEmoji") - return l + emoji.wantsLayer = true + emoji.stringValue = "🌏" + emoji.isBordered = false + emoji.isEditable = false + emoji.focusRingType = .none + emoji.alignment = .center + emoji.font = NSFont.systemFont(ofSize: 80) + emoji.backgroundColor = .clear + emoji.setAccessibilityIdentifier("NoTimezoneEmoji") + return emoji }() private lazy var message: NSTextField = { - let m = NSTextField(frame: NSRect(x: frame.size.width / 2 - 250, + let messageField = NSTextField(frame: NSRect(x: frame.size.width / 2 - 250, y: frame.size.height / 2 - 275, width: 500, height: 200)) - m.wantsLayer = true - m.setAccessibilityIdentifier("NoTimezoneMessage") - m.placeholderString = "No places added" - m.stringValue = "No places added" - m.isBordered = false - m.isEditable = false - m.maximumNumberOfLines = 2 - m.focusRingType = .none - m.alignment = .center - m.font = NSFont(name: "Avenir", size: 24) - m.backgroundColor = .clear - m.textColor = .darkGray - return m + messageField.wantsLayer = true + messageField.setAccessibilityIdentifier("NoTimezoneMessage") + messageField.placeholderString = "No places added" + messageField.stringValue = "No places added" + messageField.isBordered = false + messageField.isEditable = false + messageField.maximumNumberOfLines = 2 + messageField.focusRingType = .none + messageField.alignment = .center + messageField.font = NSFont(name: "Avenir", size: 24) + messageField.backgroundColor = .clear + messageField.textColor = .darkGray + return messageField }() override func layout() { diff --git a/Clocker/Panel/UI/TimezoneCellView.swift b/Clocker/Panel/UI/TimezoneCellView.swift index 44322ad..a0f265f 100644 --- a/Clocker/Panel/UI/TimezoneCellView.swift +++ b/Clocker/Panel/UI/TimezoneCellView.swift @@ -132,10 +132,10 @@ class TimezoneCellView: NSTableCellView { let count = range.length let currentRow = labs(rowNumber + 1 - count) - let y = CGFloat(currentRow * 68 + 34) + let yCoordinate = CGFloat(currentRow * 68 + 34) let relativeRect = CGRect(x: 0, - y: y, + y: yCoordinate, width: frame.size.width, height: frame.size.height) diff --git a/Clocker/Preferences/General/PreferencesViewController.swift b/Clocker/Preferences/General/PreferencesViewController.swift index fc35599..39c5acb 100644 --- a/Clocker/Preferences/General/PreferencesViewController.swift +++ b/Clocker/Preferences/General/PreferencesViewController.swift @@ -473,7 +473,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate UserDefaults.standard.set(filteredMenubars, forKey: CLMenubarFavorites) - if let appDelegate = NSApplication.shared.delegate as? AppDelegate, let menubarFavourites = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data], menubarFavourites.count <= 0, DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false { + if let appDelegate = NSApplication.shared.delegate as? AppDelegate, let menubarFavourites = DataStore.shared().retrieve(key: CLMenubarFavorites) as? [Data], menubarFavourites.isEmpty, DataStore.shared().shouldDisplay(.showMeetingInMenubar) == false { appDelegate.invalidateMenubarTimer(true) } @@ -624,7 +624,7 @@ extension PreferencesViewController { @objc private func search() { var searchString = searchField.stringValue - if searchString.count <= 0 { + if searchString.isEmpty { dataTask?.cancel() resetSearchView() return