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. 16
      Clocker/ClockerUITests/FloatingWindowTests.swift
  5. 2
      Clocker/ClockerUnitTests/ClockerUnitTests.swift
  6. 20
      Clocker/Dependencies/Date Additions/Date+Manipulations.swift
  7. 8
      Clocker/Dependencies/Date Additions/TimeChunk.swift
  8. 8
      Clocker/Dependencies/Solar.swift
  9. 4
      Clocker/Events and Reminders/CalendarHandler.swift
  10. 6
      Clocker/Menu Bar/StatusItemHandler.swift
  11. 8
      Clocker/Menu Bar/StatusItemView.swift
  12. 6
      Clocker/Onboarding/OnboardingParentViewController.swift
  13. 2
      Clocker/Overall App/DataStore.swift
  14. 2
      Clocker/Panel/Data Layer/TimezoneData.swift
  15. 6
      Clocker/Panel/Notes Popover/NotesPopover.swift
  16. 12
      Clocker/Panel/PanelController.swift
  17. 2
      Clocker/Panel/ParentPanelController.swift
  18. 4
      Clocker/Panel/UI/CustomSliderCell.swift
  19. 50
      Clocker/Panel/UI/NoTimezoneView.swift
  20. 4
      Clocker/Panel/UI/TimezoneCellView.swift
  21. 4
      Clocker/Preferences/General/PreferencesViewController.swift

4
.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

4
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() {

6
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 {

16
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..<menubarDisplayQueryCount {
if i < menubarDisplayQueryCount {
menubarDisplayQuery.element(boundBy: 0).click()
sleep(1)
}
for index in 0..<menubarDisplayQueryCount where index < menubarDisplayQueryCount {
menubarDisplayQuery.element(boundBy: 0).click()
sleep(1)
}
let appearanceTab = app.toolbars.buttons.element(boundBy: 1)
@ -149,8 +147,8 @@ class FloatingWindowTests: XCTestCase {
var previousValues: [String] = []
for i in 0 ..< tomorrow.count {
let element = tomorrow.element(boundBy: i)
for index in 0 ..< tomorrow.count {
let element = tomorrow.element(boundBy: index)
guard let supplementaryText = element.value as? String else {
continue
}
@ -165,8 +163,8 @@ class FloatingWindowTests: XCTestCase {
var newValues: [String] = []
for i in 0 ..< newTomorrow.count {
let element = newTomorrow.element(boundBy: i)
for index in 0 ..< newTomorrow.count {
let element = newTomorrow.element(boundBy: index)
guard let supplementaryText = element.value as? String else {
continue
}

2
Clocker/ClockerUnitTests/ClockerUnitTests.swift

@ -90,7 +90,7 @@ class ClockerUnitTests: XCTestCase {
func testDeletingATimezone() {
let defaults = UserDefaults.standard
guard var currentFavourites = defaults.object(forKey: CLDefaultPreferenceKey) as? [Data] else {
XCTFail("Default preferences aren't in the correct format")
return

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

@ -63,28 +63,28 @@ public extension Date {
var newDate = self
if component == .second {
newDate.second(newDate.second + 1)
newDate = newDate - 0.001
newDate -= 0.001
} else if component == .minute {
newDate.second(60)
newDate = newDate - 0.001
newDate -= 0.001
} else if component == .hour {
newDate.second(60)
newDate = newDate - 0.001
newDate -= 0.001
newDate.minute(59)
} else if component == .day {
newDate.second(60)
newDate = newDate - 0.001
newDate -= 0.001
newDate.minute(59)
newDate.hour(23)
} else if component == .month {
newDate.second(60)
newDate = newDate - 0.001
newDate -= 0.001
newDate.minute(59)
newDate.hour(23)
newDate.day(daysInMonth(date: newDate))
} else if component == .year {
newDate.second(60)
newDate = newDate - 0.001
newDate -= 0.001
newDate.minute(59)
newDate.hour(23)
newDate.month(12)
@ -160,28 +160,28 @@ public extension 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)
}
/**
* 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)))
}

8
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

8
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)

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
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
}

6
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()

8
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 {

6
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)
}
}

2
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

2
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

6
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)

12
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()
}

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.
height = 95.0
if let note = currentObject?.note, note.count <= 0 {
if let note = currentObject?.note, note.isEmpty {
height -= 30.0
}
}

4
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

50
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() {

4
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)

4
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

Loading…
Cancel
Save