Browse Source

Linting.

pull/92/head
Abhishek Banthia 6 years ago
parent
commit
d5f6cb9a9e
  1. 4
      .swiftlint.yml
  2. 4
      Clocker/AppDelegate.swift
  3. 6
      Clocker/Clocker/LocationController.swift
  4. 12
      Clocker/ClockerUITests/FloatingWindowTests.swift
  5. 20
      Clocker/Dependencies/Date Additions/Date+Manipulations.swift
  6. 8
      Clocker/Dependencies/Date Additions/TimeChunk.swift
  7. 8
      Clocker/Dependencies/Solar.swift
  8. 4
      Clocker/Events and Reminders/CalendarHandler.swift
  9. 6
      Clocker/Menu Bar/StatusItemHandler.swift
  10. 8
      Clocker/Menu Bar/StatusItemView.swift
  11. 6
      Clocker/Onboarding/OnboardingParentViewController.swift
  12. 6
      Clocker/Panel/Notes Popover/NotesPopover.swift
  13. 12
      Clocker/Panel/PanelController.swift
  14. 2
      Clocker/Panel/ParentPanelController.swift
  15. 4
      Clocker/Panel/UI/CustomSliderCell.swift
  16. 50
      Clocker/Panel/UI/NoTimezoneView.swift
  17. 4
      Clocker/Panel/UI/TimezoneCellView.swift
  18. 4
      Clocker/Preferences/General/PreferencesViewController.swift

4
.swiftlint.yml

@ -11,8 +11,8 @@ opt_in_rules: # some rules are only opt-in
- empty_count - empty_count
# included: # paths to include during linting. `--path` is ignored if present. # included: # paths to include during linting. `--path` is ignored if present.
# - Clocker # - Clocker
# excluded: # paths to ignore during linting. Takes precedence over `included`. excluded: # paths to ignore during linting. Takes precedence over `included`.
# - Carthage - Clocker/Dependencies
# - Pods # - Pods
# - Source/ExcludedFolder # - Source/ExcludedFolder
# - Source/ExcludedFile.swift # - Source/ExcludedFile.swift

4
Clocker/AppDelegate.swift

@ -96,8 +96,8 @@ open class AppDelegate : NSObject, NSApplicationDelegate {
} }
private lazy var controller: OnboardingController? = { private lazy var controller: OnboardingController? = {
let s = NSStoryboard(name: NSStoryboard.Name("Onboarding"), bundle: nil) let onboardingStoryboard = NSStoryboard(name: NSStoryboard.Name("Onboarding"), bundle: nil)
return s.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("onboardingFlow")) as? OnboardingController return onboardingStoryboard.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier("onboardingFlow")) as? OnboardingController
}() }()
private func showOnboardingFlow() { private func showOnboardingFlow() {

6
Clocker/Clocker/LocationController.swift

@ -7,9 +7,9 @@ class LocationController: NSObject {
public static let sharedInstance = LocationController() public static let sharedInstance = LocationController()
private var locationManager: CLLocationManager = { private var locationManager: CLLocationManager = {
let l = CLLocationManager() let locationManager = CLLocationManager()
l.desiredAccuracy = kCLLocationAccuracyThreeKilometers locationManager.desiredAccuracy = kCLLocationAccuracyThreeKilometers
return l return locationManager
}() }()
@objc class func sharedController() -> LocationController { @objc class func sharedController() -> LocationController {

12
Clocker/ClockerUITests/FloatingWindowTests.swift

@ -114,12 +114,10 @@ class FloatingWindowTests: XCTestCase {
let menubarDisplayQuery = app.tables.checkBoxes.matching(NSPredicate(format: "value == 1", "")) let menubarDisplayQuery = app.tables.checkBoxes.matching(NSPredicate(format: "value == 1", ""))
let menubarDisplayQueryCount = menubarDisplayQuery.count let menubarDisplayQueryCount = menubarDisplayQuery.count
for i in 0..<menubarDisplayQueryCount { for index in 0..<menubarDisplayQueryCount where index < menubarDisplayQueryCount {
if i < menubarDisplayQueryCount {
menubarDisplayQuery.element(boundBy: 0).click() menubarDisplayQuery.element(boundBy: 0).click()
sleep(1) sleep(1)
} }
}
let appearanceTab = app.toolbars.buttons.element(boundBy: 1) let appearanceTab = app.toolbars.buttons.element(boundBy: 1)
appearanceTab.click() appearanceTab.click()
@ -149,8 +147,8 @@ class FloatingWindowTests: XCTestCase {
var previousValues: [String] = [] var previousValues: [String] = []
for i in 0 ..< tomorrow.count { for index in 0 ..< tomorrow.count {
let element = tomorrow.element(boundBy: i) let element = tomorrow.element(boundBy: index)
guard let supplementaryText = element.value as? String else { guard let supplementaryText = element.value as? String else {
continue continue
} }
@ -165,8 +163,8 @@ class FloatingWindowTests: XCTestCase {
var newValues: [String] = [] var newValues: [String] = []
for i in 0 ..< newTomorrow.count { for index in 0 ..< newTomorrow.count {
let element = newTomorrow.element(boundBy: i) let element = newTomorrow.element(boundBy: index)
guard let supplementaryText = element.value as? String else { guard let supplementaryText = element.value as? String else {
continue continue
} }

20
Clocker/Dependencies/Date Additions/Date+Manipulations.swift

@ -63,28 +63,28 @@ public extension Date {
var newDate = self var newDate = self
if component == .second { if component == .second {
newDate.second(newDate.second + 1) newDate.second(newDate.second + 1)
newDate = newDate - 0.001 newDate -= 0.001
} else if component == .minute { } else if component == .minute {
newDate.second(60) newDate.second(60)
newDate = newDate - 0.001 newDate -= 0.001
} else if component == .hour { } else if component == .hour {
newDate.second(60) newDate.second(60)
newDate = newDate - 0.001 newDate -= 0.001
newDate.minute(59) newDate.minute(59)
} else if component == .day { } else if component == .day {
newDate.second(60) newDate.second(60)
newDate = newDate - 0.001 newDate -= 0.001
newDate.minute(59) newDate.minute(59)
newDate.hour(23) newDate.hour(23)
} else if component == .month { } else if component == .month {
newDate.second(60) newDate.second(60)
newDate = newDate - 0.001 newDate -= 0.001
newDate.minute(59) newDate.minute(59)
newDate.hour(23) newDate.hour(23)
newDate.day(daysInMonth(date: newDate)) newDate.day(daysInMonth(date: newDate))
} else if component == .year { } else if component == .year {
newDate.second(60) newDate.second(60)
newDate = newDate - 0.001 newDate -= 0.001
newDate.minute(59) newDate.minute(59)
newDate.hour(23) newDate.hour(23)
newDate.month(12) newDate.month(12)
@ -160,28 +160,28 @@ public extension Date {
/** /**
* Operator overload for adding a `TimeChunk` to a date. * Operator overload for adding a `TimeChunk` to a date.
*/ */
static func +(leftAddend: Date, rightAddend: TimeChunk) -> Date { static func + (leftAddend: Date, rightAddend: TimeChunk) -> Date {
return leftAddend.add(rightAddend) return leftAddend.add(rightAddend)
} }
/** /**
* Operator overload for subtracting a `TimeChunk` from a date. * 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) return minuend.subtract(subtrahend)
} }
/** /**
* Operator overload for adding a `TimeInterval` to a date. * 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))) return leftAddend.addingTimeInterval((TimeInterval(rightAddend)))
} }
/** /**
* Operator overload for subtracting a `TimeInterval` from a date. * 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))) return minuend.addingTimeInterval(-(TimeInterval(subtrahend)))
} }

8
Clocker/Dependencies/Date Additions/TimeChunk.swift

@ -242,28 +242,28 @@ public struct TimeChunk {
/** /**
* Operator overload for adding two `TimeChunk`s * 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) return leftAddend.lengthened(by: rightAddend)
} }
/** /**
* Operator overload for subtracting two `TimeChunk`s * 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) return minuend.shortened(by: subtrahend)
} }
/** /**
* Operator overload for checking if two `TimeChunk`s are equal * 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) return left.equals(chunk: right)
} }
/** /**
* Operator overload for inverting (negating all variables) a `TimeChunk` * 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 var invertedChunk = chunk
invertedChunk.seconds = -chunk.seconds invertedChunk.seconds = -chunk.seconds
invertedChunk.minutes = -chunk.minutes invertedChunk.minutes = -chunk.minutes

8
Clocker/Dependencies/Solar.swift

@ -98,12 +98,12 @@ public struct Solar {
rightAscenscion = normalise(rightAscenscion, withMaximum: 360) rightAscenscion = normalise(rightAscenscion, withMaximum: 360)
// Right ascension value needs to be in the same quadrant as L... // Right ascension value needs to be in the same quadrant as L...
let Lquadrant = floor(longitude / 90) * 90 let leftQuadrant = floor(longitude / 90) * 90
let RAquadrant = floor(rightAscenscion / 90) * 90 let rightQuadrant = floor(rightAscenscion / 90) * 90
rightAscenscion = rightAscenscion + (Lquadrant - RAquadrant) rightAscenscion += (leftQuadrant - rightQuadrant)
// Convert RA into hours // Convert RA into hours
rightAscenscion = rightAscenscion / 15 rightAscenscion /= 15
// Calculate Sun's declination // Calculate Sun's declination
let sinDec = 0.39782 * sin(longitude.degreesToRadians) let sinDec = 0.39782 * sin(longitude.degreesToRadians)

4
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 // We now sort the array so that AllDay Events are first, then sort by startTime
for date in eventsForDateMapper.keys { for date in eventsForDateMapper.keys {
let sortedEvents = eventsForDateMapper[date]?.sorted(by: { (e1, e2) -> Bool in let sortedEvents = eventsForDateMapper[date]?.sorted(by: { (event1, event2) -> Bool in
if e1.isAllDay { return true } else if e2.isAllDay { return false } else { return e1.event.startDate < e2.event.startDate } if event1.isAllDay { return true } else if event2.isAllDay { return false } else { return event1.event.startDate < event2.event.startDate }
}) })
eventsForDateMapper[date] = sortedEvents eventsForDateMapper[date] = sortedEvents
} }

6
Clocker/Menu Bar/StatusItemHandler.swift

@ -15,9 +15,9 @@ class StatusItemHandler: NSObject {
var menubarTimer: Timer? var menubarTimer: Timer?
var statusItem: NSStatusItem = { var statusItem: NSStatusItem = {
let s = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength) let statusItem = NSStatusBar.system.statusItem(withLength: NSStatusItem.variableLength)
s.highlightMode = false statusItem.highlightMode = false
return s return statusItem
}() }()
private var menubarTitleHandler = MenubarHandler() private var menubarTitleHandler = MenubarHandler()

8
Clocker/Menu Bar/StatusItemView.swift

@ -3,10 +3,10 @@
import Cocoa import Cocoa
private var defaultParagraphStyle: NSMutableParagraphStyle { private var defaultParagraphStyle: NSMutableParagraphStyle {
let p = NSMutableParagraphStyle() let paragraphStyle = NSMutableParagraphStyle()
p.alignment = .center paragraphStyle.alignment = .center
p.lineBreakMode = .byTruncatingTail paragraphStyle.lineBreakMode = .byTruncatingTail
return p return paragraphStyle
} }
var compactModeTimeFont: NSFont { var compactModeTimeFont: NSFont {

6
Clocker/Onboarding/OnboardingParentViewController.swift

@ -177,9 +177,9 @@ class OnboardingParentViewController: NSViewController {
} }
} }
private func addChildIfNeccessary(_ vc: NSViewController) { private func addChildIfNeccessary(_ viewController: NSViewController) {
if children.contains(vc) == false { if children.contains(viewController) == false {
addChild(vc) addChild(viewController)
} }
} }

6
Clocker/Panel/Notes Popover/NotesPopover.swift

@ -292,7 +292,7 @@ class NotesPopover: NSViewController {
let menubarIndex = timezones.firstIndex { (menubarLocation) -> Bool in let menubarIndex = timezones.firstIndex { (menubarLocation) -> Bool in
if let convertedObject = TimezoneData.customObject(from: menubarLocation) { if let convertedObject = TimezoneData.customObject(from: menubarLocation) {
return convertedObject == dataObject return convertedObject.isEqual(dataObject)
} }
return false 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 ? overrideType == .timezoneFormat ?
timezoneObject.setShouldOverrideGlobalTimeFormat(override) : timezoneObject.setShouldOverrideGlobalTimeFormat(override) :
timezoneObject.setShouldOverrideSecondsFormat(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 ? overrideType == .timezoneFormat ?
timezoneObject.setShouldOverrideGlobalTimeFormat(override) : timezoneObject.setShouldOverrideGlobalTimeFormat(override) :
timezoneObject.setShouldOverrideSecondsFormat(override) timezoneObject.setShouldOverrideSecondsFormat(override)

12
Clocker/Panel/PanelController.swift

@ -46,16 +46,16 @@ class PanelController: ParentPanelController {
func setFrameTheNewWay(_ rect: NSRect, _ maxX: CGFloat) { func setFrameTheNewWay(_ rect: NSRect, _ maxX: CGFloat) {
// Calculate window's top left point. // Calculate window's top left point.
// First, center window under status item. // First, center window under status item.
let w = (window?.frame)!.width let width = (window?.frame)!.width
var x = CGFloat(roundf(Float(rect.midX - w / 2))) var xPoint = CGFloat(roundf(Float(rect.midX - width / 2)))
let y = CGFloat(rect.minY - 2) let yPoint = CGFloat(rect.minY - 2)
let kMinimumSpaceBetweenWindowAndScreenEdge: CGFloat = 10 let kMinimumSpaceBetweenWindowAndScreenEdge: CGFloat = 10
if x + w + kMinimumSpaceBetweenWindowAndScreenEdge > maxX { if xPoint + width + kMinimumSpaceBetweenWindowAndScreenEdge > maxX {
x = maxX - w - kMinimumSpaceBetweenWindowAndScreenEdge xPoint = maxX - width - kMinimumSpaceBetweenWindowAndScreenEdge
} }
window?.setFrameTopLeftPoint(NSPoint(x: x, y: y)) window?.setFrameTopLeftPoint(NSPoint(x: xPoint, y: yPoint))
window?.invalidateShadow() window?.invalidateShadow()
} }

2
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. // Set it to 95 expicity in case the row height is calculated be higher.
height = 95.0 height = 95.0
if let note = currentObject?.note, note.count <= 0 { if let note = currentObject?.note, note.isEmpty {
height -= 30.0 height -= 30.0
} }
} }

4
Clocker/Panel/UI/CustomSliderCell.swift

@ -20,12 +20,12 @@ class CustomSliderCell: NSSliderCell {
var leftRect = rect var leftRect = rect
leftRect.size.width = finalWidth leftRect.size.width = finalWidth
let bg = NSBezierPath(roundedRect: rect, let background = NSBezierPath(roundedRect: rect,
xRadius: barRadius, xRadius: barRadius,
yRadius: barRadius) yRadius: barRadius)
NSColor(calibratedRed: 67.0 / 255.0, green: 138.0 / 255.0, blue: 250.0 / 255.0, alpha: 1.0).setFill() 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 // Right Part

50
Clocker/Panel/UI/NoTimezoneView.swift

@ -5,40 +5,40 @@ import QuartzCore
class NoTimezoneView: NSView { class NoTimezoneView: NSView {
private lazy var emoji: NSTextField = { 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, y: frame.size.height / 2 - 50,
width: 100, width: 100,
height: 100)) height: 100))
l.wantsLayer = true emoji.wantsLayer = true
l.stringValue = "🌏" emoji.stringValue = "🌏"
l.isBordered = false emoji.isBordered = false
l.isEditable = false emoji.isEditable = false
l.focusRingType = .none emoji.focusRingType = .none
l.alignment = .center emoji.alignment = .center
l.font = NSFont.systemFont(ofSize: 80) emoji.font = NSFont.systemFont(ofSize: 80)
l.backgroundColor = .clear emoji.backgroundColor = .clear
l.setAccessibilityIdentifier("NoTimezoneEmoji") emoji.setAccessibilityIdentifier("NoTimezoneEmoji")
return l return emoji
}() }()
private lazy var message: NSTextField = { 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, y: frame.size.height / 2 - 275,
width: 500, width: 500,
height: 200)) height: 200))
m.wantsLayer = true messageField.wantsLayer = true
m.setAccessibilityIdentifier("NoTimezoneMessage") messageField.setAccessibilityIdentifier("NoTimezoneMessage")
m.placeholderString = "No places added" messageField.placeholderString = "No places added"
m.stringValue = "No places added" messageField.stringValue = "No places added"
m.isBordered = false messageField.isBordered = false
m.isEditable = false messageField.isEditable = false
m.maximumNumberOfLines = 2 messageField.maximumNumberOfLines = 2
m.focusRingType = .none messageField.focusRingType = .none
m.alignment = .center messageField.alignment = .center
m.font = NSFont(name: "Avenir", size: 24) messageField.font = NSFont(name: "Avenir", size: 24)
m.backgroundColor = .clear messageField.backgroundColor = .clear
m.textColor = .darkGray messageField.textColor = .darkGray
return m return messageField
}() }()
override func layout() { override func layout() {

4
Clocker/Panel/UI/TimezoneCellView.swift

@ -132,10 +132,10 @@ class TimezoneCellView: NSTableCellView {
let count = range.length let count = range.length
let currentRow = labs(rowNumber + 1 - count) let currentRow = labs(rowNumber + 1 - count)
let y = CGFloat(currentRow * 68 + 34) let yCoordinate = CGFloat(currentRow * 68 + 34)
let relativeRect = CGRect(x: 0, let relativeRect = CGRect(x: 0,
y: y, y: yCoordinate,
width: frame.size.width, width: frame.size.width,
height: frame.size.height) height: frame.size.height)

4
Clocker/Preferences/General/PreferencesViewController.swift

@ -473,7 +473,7 @@ extension PreferencesViewController: NSTableViewDataSource, NSTableViewDelegate
UserDefaults.standard.set(filteredMenubars, forKey: CLMenubarFavorites) 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) appDelegate.invalidateMenubarTimer(true)
} }
@ -624,7 +624,7 @@ extension PreferencesViewController {
@objc private func search() { @objc private func search() {
var searchString = searchField.stringValue var searchString = searchField.stringValue
if searchString.count <= 0 { if searchString.isEmpty {
dataTask?.cancel() dataTask?.cancel()
resetSearchView() resetSearchView()
return return

Loading…
Cancel
Save