Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# https://github.com/nicklockwood/SwiftFormat/blob/master/Rules.md

# format options

--symlinks ignore
--swiftversion 6.2

# format options

--closingparen same-line
--commas inline
--comments indent
--decimalgrouping 3,4
--exponentcase lowercase
--exponentgrouping disabled
--fractiongrouping disabled
--ifdef no-indent
--importgrouping testable-top
--nospaceoperators ..<, ...
--selfrequired validate
--stripunusedargs closure-only
--wraparguments after-first
--wrapcollections after-first
--wrapparameters after-first
--disable wrapArguments
--indent 4
--maxwidth 115
--wrapcollections before-first
--ranges no-space

# rules

--disable wrapMultilineStatementBraces


--enable isEmpty,\
blankLineAfterImports,\
sortSwitchCases,\
redundantAsync,\

207 changes: 207 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,207 @@
# You can find the documentation here :
# https://realm.github.io/SwiftLint/rule-directory.html

##############
#Disabled rules#
##############

disabled_rules:
- nesting

##############
#Opted in rules#
##############

opt_in_rules:
- array_init
- closure_spacing
- collection_alignment
- contains_over_filter_count
- contains_over_filter_is_empty
- contains_over_first_not_nil
- contains_over_range_nil_comparison
- convenience_type
- discouraged_object_literal
- discouraged_optional_boolean
- empty_collection_literal
- empty_count
- empty_xctest_method
- enum_case_associated_values_count
- expiring_todo
- explicit_init
- extension_access_modifier
- fallthrough
- fatal_error_message
- file_name_no_space
- first_where
- flatmap_over_map_reduce
- force_unwrapping
- ibinspectable_in_extension
- identical_operands
- implicit_return
- joined_default_parameter
- last_where
- legacy_multiple
- legacy_random
- let_var_whitespace
- literal_expression_end_indentation
- multiline_arguments
- multiline_parameters
- nimble_operator
- nslocalizedstring_key
- nslocalizedstring_require_bundle
- number_separator
- operator_usage_whitespace
- optional_enum_case_matching
- overridden_super_call
- override_in_extension
- pattern_matching_keywords
- prefer_self_type_over_type_of_self
- prefer_zero_over_explicit_init
- prefixed_toplevel_constant
- private_action
- private_outlet
- prohibited_super_call
- quick_discouraged_call
- quick_discouraged_focused_test
- quick_discouraged_pending_test
- raw_value_for_camel_cased_codable_enum
- reduce_into
- redundant_nil_coalescing
- redundant_type_annotation
- required_enum_case
- single_test_class
- sorted_first_last
- sorted_imports
- static_operator
- toggle_bool
- trailing_closure
- unavailable_function
- unneeded_parentheses_in_closure_argument
- untyped_error_in_catch
- vertical_parameter_alignment_on_call
- vertical_whitespace_closing_braces
- vertical_whitespace_opening_braces
- xct_specific_matcher
- yoda_condition
- unhandled_throwing_task

##############
#Specific analyzer rules#
##############

analyzer_rules: # Rules run by `swiftlint analyze`
- explicit_self
- unused_declaration
- unused_import

################
#Customed rules#
################

# configurable rules can be customized from this configuration file
# binary rules can set their severity level
#force_cast: warning # implicitly

#force_try:
# severity: warning # explicitly
#
# rules that have both warning and error levels, can set just the warning level
# implicitly
line_length:
warning: 120
error: 200
ignores_urls: true
ignores_comments: true

# they can set both implicitly with an array
type_body_length:
warning: 300
error: 400

trailing_closure:
only_single_muted_parameter: true

trailing_whitespace:
ignores_empty_lines: true

# or they can set both explicitly
file_length:
warning: 700
error: 1200

function_body_length: # Functions bodies should not span too many lines.
warning: 100
error: 200

# naming rules can set warnings/errors for min_length and max_length
# additionally they can set excluded names
type_name:
min_length: 3 # only warning
max_length: # warning and error
warning: 45
error: 50
excluded: iPhone # excluded via string
allowed_symbols: ["_"] # these are allowed in type names

identifier_name:
min_length: # only min_length
warning: 2
excluded: # excluded via string array
reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit, html, emoji, sonarqube, markdown)

custom_rules:
drop_first_one:
name: "Drop first one"
message: "Implicitly drop first one element"
regex: "(\\.dropFirst\\(1\\))"

discouraged_optional_self:
name: "Discouraged optional self"
message: "Unwrap self via guard let and use implicit self instead of optional self"
regex: "(self\\?\\.)"

discouraged_previewprovider:
name: "Discouraged PreviewProvider"
message: "Use #Preview macro insteaf of PreviewProvider"
regex: "(PreviewProvider)"

discouraged_anyview:
name: "Discouraged AnyView"
message: "Avoid using AnyView for better performance"
regex: "(AnyView)"

discouraged_body_font:
name: "Discouraged body font"
message: "Prefer implicit body font"
regex: "(\\.font\\(\\.body\\))"

discouraged_regular_font_weight:
name: "Discouraged regular font weight"
message: "Prefer implicit regular font weight"
regex: "(\\.fontWeight\\(\\.regular\\))"

discouraged_verbose_contentshape_rectangle:
name: "Discouraged verbose .contentShape(Rectangle())"
message: "Prefer static member lookup version .contentShape(.rectangle)"
regex: "(\\.contentShape\\(Rectangle\\(\\))"

deprecated_foregroundcolor_modifier:
name: "Deprecated foregroundColor modifier"
message: "Prefer foregroundStyle over deprecated foregroundColor"
regex: "(foregroundColor\\()"

deprecated_navigationbarleading:
name: "Deprecated navigationBarLeading"
message: "Prefer topBarLeading over deprecated navigationBarLeading"
regex: "\\.navigationBarLeading"

deprecated_navigationbartrailing:
name: "Deprecated navigationBarTrailing"
message: "Prefer topBarTrailing over deprecated navigationBarTrailing"
regex: "\\.navigationBarTrailing"

nil_if_empty:
name: "Nil if empty"
message: "Use Collection's computed property nilIfEmpty"
regex: "\\.isEmpty \\? nil"
2 changes: 1 addition & 1 deletion SimpleLogin/Keyboard Extension/CreatedAliasView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct CreatedAliasView: View {
}, label: {
Label("Back", systemImage: "arrowshape.turn.up.backward.fill")
})
.foregroundColor(.slPurple)
.foregroundColor(.slPurple)
}
.padding(.horizontal, 44)
}
Expand Down
8 changes: 4 additions & 4 deletions SimpleLogin/Keyboard Extension/KeyboardContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ struct KeyboardContentView: View {

init(session: Session, onTap: @escaping (Alias) -> Void) {
_viewModel = StateObject(wrappedValue: .init(session: session))
self.onSelectAlias = onTap
onSelectAlias = onTap
}

var body: some View {
Expand All @@ -31,7 +31,7 @@ struct KeyboardContentView: View {
}, label: {
Label("Retry", systemImage: "gobackward")
})
.foregroundColor(.slPurple)
.foregroundColor(.slPurple)
}
.padding()
} else {
Expand Down Expand Up @@ -69,7 +69,7 @@ final class KeyboardContentViewModel: ObservableObject {
}

func getMoreAliasesIfNeed(currentAlias alias: Alias?) {
guard let alias = alias else {
guard let alias else {
getMoreAliases()
return
}
Expand All @@ -81,7 +81,7 @@ final class KeyboardContentViewModel: ObservableObject {
}

private func getMoreAliases() {
guard !isLoading && canLoadMorePages else { return }
guard !isLoading, canLoadMorePages else { return }
Task { @MainActor in
defer { isLoading = false }
isLoading = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ final class KeyboardViewController: UIInputViewController {

private func setSession(session: Session?) {
let subView: UIView
if let session = session {
if let session {
let contentView = KeyboardContentView(session: session) { [unowned self] alias in
textDocumentProxy.insertText(alias.email)
}
Expand Down
29 changes: 14 additions & 15 deletions SimpleLogin/ShareExtension/ShareViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ final class ShareViewController: UIViewController {
self.setUpUI()
} catch {
alert(error: error) { [unowned self] in
self.dismiss()
dismiss()
}
}
}
Expand All @@ -42,17 +42,16 @@ final class ShareViewController: UIViewController {

private func setSession(session: Session?) {
let subView: UIView
if let session = session {
let createAliasView = CreateAliasView(
session: session,
mode: createAliasViewMode,
onCreateAlias: { [unowned self] alias in
self.handleAliasCreation(alias: alias)
},
onCancel: { [unowned self] in
self.dismiss()
},
onOpenMyAccount: nil)
if let session {
let createAliasView = CreateAliasView(session: session,
mode: createAliasViewMode,
onCreateAlias: { [unowned self] alias in
handleAliasCreation(alias: alias)
},
onCancel: { [unowned self] in
dismiss()
},
onOpenMyAccount: nil)
let hostingController = UIHostingController(rootView: createAliasView)
subView = hostingController.view
addChild(hostingController)
Expand Down Expand Up @@ -114,19 +113,19 @@ final class ShareViewController: UIViewController {
preferredStyle: .alert)
let copyAndCloseAction = UIAlertAction(title: "Copy & close", style: .default) { [unowned self] _ in
UIPasteboard.general.string = alias.email
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
}
alert.addAction(copyAndCloseAction)

let closeAction = UIAlertAction(title: "Close", style: .cancel) { [unowned self] _ in
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
}
alert.addAction(closeAction)
alert.view.tintColor = .slPurple
present(alert, animated: true, completion: nil)
}

private func dismiss() {
self.extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
extensionContext?.completeRequest(returningItems: nil, completionHandler: nil)
}
}
6 changes: 3 additions & 3 deletions SimpleLogin/SimpleLogin/AppDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import SwiftyStoreKit
import UIKit

final class AppDelegate: NSObject, UIApplicationDelegate {
func application(_ application: UIApplication,
func application(_: UIApplication,
// swiftlint:disable:next line_length
didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
didFinishLaunchingWithOptions _: [UIApplication.LaunchOptionsKey: Any]? = nil) -> Bool {
UIView.appearance(whenContainedInInstancesOf:
[UIAlertController.self]).tintColor = .slPurple
[UIAlertController.self]).tintColor = .slPurple
SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
for purchase in purchases {
switch purchase.transaction.transactionState {
Expand Down
Loading
Loading