Skip to content

Commit

Permalink
Swiftlint fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
leits committed Oct 23, 2022
1 parent 87e3035 commit a1d751d
Show file tree
Hide file tree
Showing 12 changed files with 156 additions and 205 deletions.
163 changes: 11 additions & 152 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,148 +1,20 @@

whitelist_rules:
- anyobject_protocol
- array_init
- attributes
- block_based_kvo
- class_delegate_protocol
- closing_brace
- closure_end_indentation
- closure_parameter_position
- closure_spacing
- collection_alignment
- colon
- comma
- compiler_protocol_init
- conditional_returns_on_newline
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- control_statement
- custom_rules
- deployment_target
- discarded_notification_center_observer
- discouraged_direct_init
- discouraged_object_literal
- discouraged_optional_collection
- duplicate_enum_cases
- duplicate_imports
- dynamic_inline
- empty_collection_literal
- empty_count
- empty_enum_arguments
- empty_parameters
- empty_parentheses_with_trailing_closure
- empty_string
- empty_xctest_method
- enum_case_associated_value_count
- explicit_init
- fallthrough
- fatal_error_message
- first_where
- flatmap_over_map_reduce
- for_where
- generic_type_name
- identical_operands
- identifier_name
- implicit_getter
- implicit_return
- inert_defer
- is_disjoint
- joined_default_parameter
- last_where
- leading_whitespace
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_multiple
- legacy_nsgeometry_functions
- legacy_random
- literal_expression_end_indentation
- lower_acl_than_parent
- mark
- modifier_order
- multiline_arguments
- multiline_function_chains
- multiline_literal_brackets
- multiline_parameters
- multiline_parameters_brackets
- nimble_operator
- no_extension_access_modifier
- no_fallthrough_only
- no_space_in_method_call
- notification_center_detachment
- nsobject_prefer_isequal
disabled_rules:
- force_try
- multiple_closures_with_trailing_closure
- force_cast
- cyclomatic_complexity
- type_name
- file_length
- function_body_length
- type_body_length
opt_in_rules:
- number_separator
- opening_brace
- operator_usage_whitespace
- operator_whitespace
- orphaned_doc_comment
- overridden_super_call
- prefer_self_type_over_type_of_self
- private_action
- private_outlet
- private_unit_test
- prohibited_nan_comparison
- prohibited_super_call
- protocol_property_accessors_order
- reduce_boolean
- reduce_into
- redundant_discardable_let
- redundant_nil_coalescing
- redundant_objc_attribute
- redundant_optional_initialization
- redundant_set_access_control
- redundant_string_enum_value
- redundant_type_annotation
- redundant_void_return
- required_enum_case
- return_value_from_void_function
- return_arrow_whitespace
- shorthand_operator
- sorted_first_last
- statement_position
- static_operator
- strong_iboutlet
- superfluous_disable_command
- switch_case_alignment
- switch_case_on_newline
- syntactic_sugar
- todo
- toggle_bool
- trailing_closure
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- tuple_pattern
- unavailable_function
- unneeded_break_in_switch
- unneeded_parentheses_in_closure_argument
- unowned_variable_capture
- untyped_error_in_catch
- unused_capture_list
- unused_closure_parameter
- unused_control_flow_label
- unused_enumerated
- unused_optional_binding
- unused_setter_value
- valid_ibinspectable
- vertical_parameter_alignment
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- void_return
- weak_delegate
- xct_specific_matcher
- xctfail_message
- yoda_condition
analyzer_rules:
- unused_declaration
- unused_import
number_separator:
minimum_length: 5
line_length: 200
identifier_name:
max_length:
warning: 100
Expand All @@ -162,16 +34,3 @@ identifier_name:
- 'x2'
- 'y1'
- 'y2'
custom_rules:
no_nsrect:
regex: '\bNSRect\b'
match_kinds: typeidentifier
message: 'Use CGRect instead of NSRect'
no_nssize:
regex: '\bNSSize\b'
match_kinds: typeidentifier
message: 'Use CGSize instead of NSSize'
no_nspoint:
regex: '\bNSPoint\b'
match_kinds: typeidentifier
message: 'Use CGPoint instead of NSPoint'
25 changes: 24 additions & 1 deletion MeetingBar.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 @@ -372,6 +372,7 @@
144C01762462D0C3000C9FFC /* Frameworks */,
144C01772462D0C3000C9FFC /* Resources */,
40DC7050250E5D8D00217DD9 /* CopyFiles */,
467351B529055E9900EE3987 /* Run Script */,
);
buildRules = (
);
Expand Down Expand Up @@ -512,6 +513,28 @@
};
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
467351B529055E9900EE3987 /* Run Script */ = {
isa = PBXShellScriptBuildPhase;
alwaysOutOfDate = 1;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
);
name = "Run Script";
outputFileListPaths = (
);
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "# Type a script or drag a script file from your workspace to insert its path.\nexport PATH=\"$PATH:/opt/homebrew/bin\"\nif which swiftlint > /dev/null; then\n swiftlint --fix && swiftlint\nelse\n echo \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi\n";
};
/* End PBXShellScriptBuildPhase section */

/* Begin PBXSourcesBuildPhase section */
144C01752462D0C3000C9FFC /* Sources */ = {
isa = PBXSourcesBuildPhase;
Expand Down
13 changes: 9 additions & 4 deletions MeetingBar/ActionsOnEventStart.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,11 @@ class ActionsOnEventStart: NSObject {
if autoJoinActionActive && (nonAlldayCandidateForAutoJoin || allDayCandidate) {
var events = Defaults[.processedEventsForAutoJoin]

let matchedEvent = events.filter { $0.id == nextEvent.ID }.first
let matchedEvent = events.first { $0.id == nextEvent.ID }

// if a script was executed already for the event, but the start date is different, we will remove the the current event from the scheduled events, so that we can run the script again -> this is an edge case when the event was already notified for, but scheduled for a later time.
// if a script was executed already for the event, but the start date is different,
// we will remove the the current event from the scheduled events, so that we can run the script again ->
// this is an edge case when the event was already notified for, but scheduled for a later time.
if matchedEvent == nil || matchedEvent?.lastModifiedDate != nextEvent.lastModifiedDate {
if nextEvent.meetingLink != nil {
nextEvent.openMeeting()
Expand All @@ -90,9 +92,12 @@ class ActionsOnEventStart: NSObject {
if runEventStartScriptActionActive, nonAlldayCandidateForRunStartEventScript || allDayCandidate {
var events = Defaults[.processedEventsForRunScriptOnEventStart]

let matchedEvent = events.filter { $0.id == nextEvent.ID }.first
let matchedEvent = events.first { $0.id == nextEvent.ID }

// if a script was executed already for the event, but the start date is different, we will remove the the current event from the scheduled events, so that we can run the script again -> this is an edge case when the event was already notified for, but scheduled for a later time.
// if a script was executed already for the event, but the start date is different,
// we will remove the the current event from the scheduled events,
// so that we can run the script again ->
// this is an edge case when the event was already notified for, but scheduled for a later time.
if matchedEvent == nil || matchedEvent?.lastModifiedDate != nextEvent.lastModifiedDate {
runMeetingStartsScript(event: nextEvent, type: ScriptType.meetingStart)

Expand Down
28 changes: 23 additions & 5 deletions MeetingBar/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,15 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
}

// Settings change observers
appearanceSettingsObserver = Defaults.observe(keys: .statusbarEventTitleLength, .eventTimeFormat, .eventTitleIconFormat, .showEventMaxTimeUntilEventThreshold, .showEventMaxTimeUntilEventEnabled, .showEventDetails, .shortenEventTitle, .menuEventTitleLength, .showEventEndTime, .showMeetingServiceIcon, .timeFormat, .bookmarks, .eventTitleFormat, options: []) {
appearanceSettingsObserver = Defaults.observe(
keys: .statusbarEventTitleLength, .eventTimeFormat,
.eventTitleIconFormat, .showEventMaxTimeUntilEventThreshold,
.showEventMaxTimeUntilEventEnabled, .showEventDetails,
.shortenEventTitle, .menuEventTitleLength,
.showEventEndTime, .showMeetingServiceIcon,
.timeFormat, .bookmarks, .eventTitleFormat,
options: []
) {
self.statusBarItem.updateTitle()
self.statusBarItem.updateMenu()
}
Expand All @@ -127,7 +135,14 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
SMLoginItemSetEnabled(AutoLauncher.bundleIdentifier as CFString, change.newValue)
}
}
eventFiltersObserver = Defaults.observe(keys: .selectedCalendarIDs, .showEventsForPeriod, .disablePastEvents, .pastEventsAppereance, .declinedEventsAppereance, .showPendingEvents, .allDayEvents, .nonAllDayEvents, .personalEventsAppereance, .showEventsForPeriod, options: []) {
eventFiltersObserver = Defaults.observe(
keys: .selectedCalendarIDs, .showEventsForPeriod,
.disablePastEvents, .pastEventsAppereance,
.declinedEventsAppereance, .showPendingEvents,
.allDayEvents, .nonAllDayEvents,
.personalEventsAppereance, .showEventsForPeriod,
options: []
) {
self.statusBarItem.loadCalendars()
}
preferredLanguageObserver = Defaults.observe(.preferredLanguage) { change in
Expand Down Expand Up @@ -161,7 +176,10 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
eventStore = GCEventStore.shared

NotificationCenter.default.removeObserver(self, name: .EKEventStoreChanged, object: EKEventStore.shared)
NSAppleEventManager.shared().setEventHandler(self, andSelector: #selector(handleURLEvent(getURLEvent:replyEvent:)), forEventClass: AEEventClass(kInternetEventClass), andEventID: AEEventID(kAEGetURL))
NSAppleEventManager.shared().setEventHandler(self,
andSelector: #selector(handleURLEvent(getURLEvent:replyEvent:)),
forEventClass: AEEventClass(kInternetEventClass),
andEventID: AEEventID(kAEGetURL))
}
}

Expand Down Expand Up @@ -197,7 +215,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
case "JOIN_ACTION", UNNotificationDefaultActionIdentifier:
if response.notification.request.content.categoryIdentifier == "EVENT" || response.notification.request.content.categoryIdentifier == "SNOOZE_EVENT" {
if let eventID = response.notification.request.content.userInfo["eventID"] as? String {
if let event = statusBarItem.events.filter({ $0.ID == eventID }).first {
if let event = statusBarItem.events.first(where: { $0.ID == eventID }) {
NSLog("Join \(event.title) event from notication")
event.openMeeting()
}
Expand All @@ -223,7 +241,7 @@ class AppDelegate: NSObject, NSApplicationDelegate, UNUserNotificationCenterDele
func handleSnoozeEvent(_ response: UNNotificationResponse, _ action: NotificationEventTimeAction) {
if response.notification.request.content.categoryIdentifier == "EVENT" || response.notification.request.content.categoryIdentifier == "SNOOZE_EVENT" {
if let eventID = response.notification.request.content.userInfo["eventID"] as? String {
if let event = statusBarItem.events.filter({ $0.ID == eventID }).first {
if let event = statusBarItem.events.first(where: { $0.ID == eventID }) {
if action.durationInSeconds == 0 {
NSLog("Snooze event until start")
} else {
Expand Down
29 changes: 22 additions & 7 deletions MeetingBar/EventStores/EKEventStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,13 @@ extension EKEventStore: EventStore {
var allCalendars: [MBCalendar] = []

for calendar in EKEventStore.shared.calendars(for: .event) {
let calendar = MBCalendar(title: calendar.title, ID: calendar.calendarIdentifier, source: calendar.source.title, email: _getGmailAccount(calendar.source.description), color: calendar.color)
let calendar = MBCalendar(
title: calendar.title,
ID: calendar.calendarIdentifier,
source: calendar.source.title,
email: _getGmailAccount(calendar.source.description),
color: calendar.color
)
allCalendars.append(calendar)
}
return seal.fulfill(allCalendars)
Expand All @@ -66,7 +72,7 @@ extension EKEventStore: EventStore {

var events: [MBEvent] = []
for rawEvent in EKEventStore.shared.events(matching: predicate) {
let calendar = calendars.first(where: { $0.ID == rawEvent.calendar.calendarIdentifier })!
let calendar = calendars.first { $0.ID == rawEvent.calendar.calendarIdentifier }!

var status: MBEventStatus
switch rawEvent.status {
Expand Down Expand Up @@ -116,11 +122,20 @@ extension EKEventStore: EventStore {
}

let event = MBEvent(
ID: rawEvent.calendarItemIdentifier, lastModifiedDate: rawEvent.lastModifiedDate,
title: rawEvent.title, status: status, notes: rawEvent.notes, location: rawEvent.location,
url: rawEvent.url, organizer: organizer, attendees: attendees,
startDate: rawEvent.startDate, endDate: rawEvent.endDate,
isAllDay: rawEvent.isAllDay, recurrent: rawEvent.hasRecurrenceRules, calendar: calendar
ID: rawEvent.calendarItemIdentifier,
lastModifiedDate: rawEvent.lastModifiedDate,
title: rawEvent.title,
status: status,
notes: rawEvent.notes,
location: rawEvent.location,
url: rawEvent.url,
organizer: organizer,
attendees: attendees,
startDate: rawEvent.startDate,
endDate: rawEvent.endDate,
isAllDay: rawEvent.isAllDay,
recurrent: rawEvent.hasRecurrenceRules,
calendar: calendar
)
events.append(event)
}
Expand Down
17 changes: 15 additions & 2 deletions MeetingBar/EventStores/Event.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,20 @@ class MBEvent {
let recurrent: Bool
var attendees: [MBEventAttendee] = []

init(ID: String, lastModifiedDate: Date?, title: String?, status: MBEventStatus, notes: String?, location: String?, url: URL?, organizer: MBEventOrganizer?, attendees: [MBEventAttendee] = [], startDate: Date, endDate: Date, isAllDay: Bool, recurrent: Bool, calendar: MBCalendar) {
init(ID: String,
lastModifiedDate: Date?,
title: String?,
status: MBEventStatus,
notes: String?,
location: String?,
url: URL?,
organizer: MBEventOrganizer?,
attendees: [MBEventAttendee] = [],
startDate: Date,
endDate: Date,
isAllDay: Bool,
recurrent: Bool,
calendar: MBCalendar) {
self.calendar = calendar
self.ID = ID
self.lastModifiedDate = lastModifiedDate
Expand Down Expand Up @@ -214,7 +227,7 @@ func getNextEvent(events: [MBEvent]) -> MBEvent? {

// Filter out personal events, if not marked as 'active'
if Defaults[.personalEventsAppereance] != .show_active {
nextEvents = nextEvents.filter { $0.attendees.count > 0 }
nextEvents = nextEvents.filter { !$0.attendees.isEmpty }
}

for event in nextEvents {
Expand Down
Loading

0 comments on commit a1d751d

Please sign in to comment.