Skip to content

Commit

Permalink
Add SwiftLint (#692)
Browse files Browse the repository at this point in the history
Add SwiftLint and fix styling errors
  • Loading branch information
mvasilak authored Jun 13, 2023
1 parent 8c109fe commit 2ad6bae
Show file tree
Hide file tree
Showing 299 changed files with 1,565 additions and 723 deletions.
282 changes: 282 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,282 @@
only_rules:
# default rules
- block_based_kvo
- closing_brace
- closure_parameter_position
- colon
- comma
- computed_accessors_order
- control_statement
- deployment_target
- discouraged_direct_init
- empty_enum_arguments
- empty_parameters
- empty_parentheses_with_trailing_closure
- implicit_getter
- leading_whitespace
- legacy_cggeometry_functions
- legacy_constant
- legacy_constructor
- legacy_hashing
- legacy_nsgeometry_functions
- legacy_random
- mark
- multiple_closures_with_trailing_closure
- no_space_in_method_call
- ns_number_init_as_function_reference
- opening_brace
- operator_whitespace
- orphaned_doc_comment
- private_over_fileprivate
- private_unit_test
- protocol_property_accessors_order
- redundant_discardable_let
- redundant_optional_initialization
- redundant_set_access_control
- redundant_string_enum_value
- redundant_void_return
- return_arrow_whitespace
- self_in_property_initialization
- shorthand_operator
- statement_position
- switch_case_alignment
- syntactic_sugar
- trailing_comma
- trailing_newline
- trailing_semicolon
- trailing_whitespace
- unavailable_condition
- unneeded_break_in_switch
- unused_closure_parameter
- unused_enumerated
- unused_optional_binding
- unused_setter_value
- vertical_parameter_alignment
- vertical_whitespace
- void_return
# opt-in rules
- anyobject_protocol
- array_init
- closure_end_indentation
- closure_spacing
- collection_alignment
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- direct_return
- discarded_notification_center_observer
- empty_collection_literal
- empty_count
- empty_string
- fallthrough
- flatmap_over_map_reduce
- identical_operands
- joined_default_parameter
- operator_usage_whitespace
- overridden_super_call
- period_spacing
- prefer_zero_over_explicit_init
- self_binding
- unused_capture_list
- vertical_parameter_alignment_on_call
- vertical_whitespace_between_cases
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- yoda_condition

anyobject_protocol: error

array_init: error

block_based_kvo: error

closing_brace: error

closure_end_indentation: error

closure_parameter_position: error

closure_spacing: error

collection_alignment:
severity: error
align_colons: false

colon:
severity: error
# flexible_right_spacing: true
# apply_to_dictionaries: false

comma: error

contains_over_first_not_nil: error

contains_over_range_nil_comparison: error

control_statement: error

deployment_target:
severity: error
iOSApplicationExtension_deployment_target: 14.7
iOS_deployment_target: 14.7

direct_return: error

discarded_notification_center_observer: error

discouraged_direct_init:
severity: error

empty_collection_literal: error

empty_count:
severity: error
only_after_dot: true

empty_enum_arguments: error

empty_parameters: error

empty_parentheses_with_trailing_closure: error

empty_string: error

fallthrough: error

flatmap_over_map_reduce: error

identical_operands: error

implicit_getter: error

joined_default_parameter: error

leading_whitespace: error

legacy_cggeometry_functions: error

legacy_constant: error

legacy_constructor: error

legacy_hashing: error

legacy_nsgeometry_functions: error

legacy_random: error

mark: error

multiple_closures_with_trailing_closure: error

no_space_in_method_call: error

ns_number_init_as_function_reference: error

opening_brace:
severity: error
allowMultilineFunc: true

operator_usage_whitespace:
severity: error
lines_look_around: 2
skip_aligned_constants: true
allowed_no_space_operators: ["...", "..<"]

operator_whitespace: error

orphaned_doc_comment: error

overridden_super_call:
severity: error
excluded: []
included: ["*"]

period_spacing: error

prefer_zero_over_explicit_init: error

private_over_fileprivate:
severity: error

private_unit_test:
warning: XCTestCase

protocol_property_accessors_order: error

redundant_discardable_let: error

redundant_optional_initialization: error

redundant_set_access_control: error

redundant_string_enum_value: error

redundant_void_return: error

return_arrow_whitespace: error

self_binding:
severity: error
bindIdentifier: self

self_in_property_initialization: error

shorthand_operator: error

statement_position:
statement_mode: default
severity: error

switch_case_alignment:
severity: error

syntactic_sugar: error

trailing_comma:
severity: error
mandatory_comma: false

trailing_newline: error

trailing_semicolon: error

trailing_whitespace:
severity: error
ignores_empty_lines: true
ignores_comments: true

unavailable_condition: error

unneeded_break_in_switch: error

unused_capture_list: error

unused_closure_parameter: error

unused_enumerated: error

unused_optional_binding:
severity: error
ignore_optional_try: false

unused_setter_value: error

vertical_parameter_alignment: error

vertical_parameter_alignment_on_call: error

vertical_whitespace:
severity: error
max_empty_lines: 1

vertical_whitespace_between_cases: error

vertical_whitespace_closing_braces:
severity: error
only_enforce_before_trivial_lines: false

vertical_whitespace_opening_braces: error

void_return: error

yoda_condition: error
4 changes: 2 additions & 2 deletions ZShare/ApiRequests/CreateItemRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ struct CreateItemRequest: ApiRequest {
return .json
}

let parameters: [String : Any]?
let parameters: [String: Any]?

var headers: [String : String]? {
var headers: [String: String]? {
return ["If-Unmodified-Since-Version": "0"]
}
}
4 changes: 3 additions & 1 deletion ZShare/Controllers/FilenameFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ struct FilenameFormatter {
return "_"
}
// Don't allow hidden files
if valid[valid.startIndex] == "." {
if valid[valid.startIndex] == "." {
return String(valid[valid.index(valid.startIndex, offsetBy: 1)..<valid.endIndex])
}
return valid
Expand All @@ -54,8 +54,10 @@ struct FilenameFormatter {
switch creators.count {
case 0:
return nil

case 1:
return creators.first?.summaryName

case 2:
return "\(creators.first?.summaryName ?? "") and \(creators.last?.summaryName ?? "")"
default:
Expand Down
5 changes: 3 additions & 2 deletions ZShare/Controllers/RedirectWebViewHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ final class RedirectWebViewHandler: NSObject {
Single<Int>.timer(self.timeout, scheduler: self.timerScheduler)
.observe(on: MainScheduler.instance)
.subscribe(onSuccess: { [weak self] _ in
guard let `self` = self else { return }
guard let self = self else { return }

DDLogInfo("RedirectWebViewHandler: redirection timed out")

Expand Down Expand Up @@ -112,7 +112,7 @@ extension RedirectWebViewHandler: WKNavigationDelegate {
case "application/pdf":
DDLogInfo("RedirectWebViewHandler: redirection detected pdf - \(navigationResponse.response.url?.absoluteString ?? "-")")
inMainThread { [weak self, weak webView] in
guard let `self` = self, let webView = webView else { return }
guard let self = self, let webView = webView else { return }

// Cancel timer
self.disposeBag = nil
Expand All @@ -126,6 +126,7 @@ extension RedirectWebViewHandler: WKNavigationDelegate {
}
// Don't load web
decisionHandler(.cancel)

default:
self.startTimer()
decisionHandler(.allow)
Expand Down
3 changes: 1 addition & 2 deletions ZShare/DbRequests/ReadRecentCollections.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ struct ReadRecentCollections: DbResponseRequest {
func process(in database: Realm) throws -> [RecentData] {
let collections = database.objects(RCollection.self).sorted(byKeyPath: "lastUsed", ascending: false)

guard collections.count > 0 else { return [] }
guard !collections.isEmpty else { return [] }

var recent: [RecentData] = []
for rCollection in collections {
Expand All @@ -44,4 +44,3 @@ struct ReadRecentCollections: DbResponseRequest {
return recent
}
}

1 change: 0 additions & 1 deletion ZShare/DbRequests/UpdateCollectionLastUsedDbRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ struct UpdateCollectionLastUsedDbRequest: DbRequest {
collection.lastUsed = Date()
}
}

Loading

0 comments on commit 2ad6bae

Please sign in to comment.