diff --git a/.swiftlint.yml b/.swiftlint.yml new file mode 100644 index 000000000..435c43760 --- /dev/null +++ b/.swiftlint.yml @@ -0,0 +1,54 @@ +disabled_rules: # rule identifiers to exclude from running + - colon + - comma + - control_statement + - missing_docs + - force_cast + - variable_name + - cyclomatic_complexity + - function_body_length + - todo +opt_in_rules: # some rules are only opt-in + - empty_count + # Find all the available rules by running: + # swiftlint rules +included: # paths to include during linting. `--path` is ignored if present. + - Lock +excluded: # paths to ignore during linting. Takes precedence over `included`. + - Carthage + - Pods + - Source/ExcludedFolder + - Source/ExcludedFile.swift + +# 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: 300 +# they can set both implicitly with an array +type_body_length: + - 300 # warning + - 400 # error +# or they can set both explicitly +file_length: + warning: 500 + error: 1200 +# naming rules can set warnings/errors for min_length and max_length +# additionally they can set excluded names +type_name: + min_length: 4 # only warning + max_length: # warning and error + warning: 40 + error: 50 + excluded: iPhone # excluded via string +variable_name: + min_length: # only min_length + error: 4 # only error + excluded: # excluded via string array + - id + - URL + - GlobalAPIKey +reporter: "xcode" # reporter type (xcode, json, csv, checkstyle, junit) diff --git a/Lock.xcodeproj/project.pbxproj b/Lock.xcodeproj/project.pbxproj index 079aa57b6..e21c7956c 100644 --- a/Lock.xcodeproj/project.pbxproj +++ b/Lock.xcodeproj/project.pbxproj @@ -735,6 +735,7 @@ 5FEAE1C21D1A5154005C0028 /* Frameworks */, 5FEAE1C31D1A5154005C0028 /* Headers */, 5FEAE1C41D1A5154005C0028 /* Resources */, + 5B73CCAE1DE742F60050963E /* ShellScript */, ); buildRules = ( ); @@ -870,6 +871,19 @@ /* End PBXResourcesBuildPhase section */ /* Begin PBXShellScriptBuildPhase section */ + 5B73CCAE1DE742F60050963E /* ShellScript */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "if which swiftlint >/dev/null; then\nswiftlint\nelse\necho \"warning: SwiftLint not installed, download from https://github.com/realm/SwiftLint\"\nfi"; + }; 5FC4348D1D1E02EF005188BC /* Auth0 */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/Lock/AuthButton.swift b/Lock/AuthButton.swift index 261089379..fca4398c8 100644 --- a/Lock/AuthButton.swift +++ b/Lock/AuthButton.swift @@ -80,7 +80,7 @@ public class AuthButton: UIView { public var onPress: (AuthButton) -> () = { _ in } - // MARK:- Style + // MARK: - Style public var size: Size { didSet { @@ -94,7 +94,7 @@ public class AuthButton: UIView { case big } - // MARK:- Initialisers + // MARK: - Initialisers public init(size: Size) { self.size = size @@ -114,7 +114,7 @@ public class AuthButton: UIView { self.layout(size: self.size) } - // MARK:- Layout + // MARK: - Layout private func layout(size: Size) { @@ -182,14 +182,14 @@ public class AuthButton: UIView { } } - // MARK:- Event + // MARK: - Event func buttonPressed(_ sender: Any) { self.onPress(self) } } -// MARK:- Color Util +// MARK: - Color Util extension UIColor { func a0_darker(_ percentage: CGFloat) -> UIColor { guard percentage >= 0 && percentage <= 1 else { return self } diff --git a/Lock/AuthCollectionView.swift b/Lock/AuthCollectionView.swift index a8de6b728..106284a8a 100644 --- a/Lock/AuthCollectionView.swift +++ b/Lock/AuthCollectionView.swift @@ -34,7 +34,7 @@ class AuthCollectionView: UIView, View { case compact } - // MARK:- Initialisers + // MARK: - Initialisers init(connections: [OAuth2Connection], mode: Mode, insets: UIEdgeInsets, customStyle: [String: AuthStyle], onAction: @escaping (String) -> ()) { self.connections = connections @@ -49,7 +49,7 @@ class AuthCollectionView: UIView, View { fatalError("init(coder:) has not been implemented") } - // MARK:- Layout + // MARK: - Layout var height: CGFloat { guard !connections.isEmpty else { return 0 } @@ -137,7 +137,6 @@ class AuthCollectionView: UIView, View { } func apply(style: Style) { - } } diff --git a/Lock/AuthStyle.swift b/Lock/AuthStyle.swift index 38566be07..5100b6283 100644 --- a/Lock/AuthStyle.swift +++ b/Lock/AuthStyle.swift @@ -79,7 +79,7 @@ public class AuthStyle { } } -// MARK:- First class social connection styles +// MARK: - First class social connection styles public extension AuthStyle { @@ -264,7 +264,7 @@ public extension AuthStyle { } } -// MARK:- AuthStyle from Strategy & Connection +// MARK: - AuthStyle from Strategy & Connection extension AuthStyle { diff --git a/Lock/CDNLoaderInteractor.swift b/Lock/CDNLoaderInteractor.swift index e8f6e59b2..1bdb6db62 100644 --- a/Lock/CDNLoaderInteractor.swift +++ b/Lock/CDNLoaderInteractor.swift @@ -96,7 +96,7 @@ struct CDNLoaderInteractor: RemoteConnectionLoader, Loggable { self.logger.error("Failed to parse \(jsonp) with error \(e)") return callback(nil) } - }) + }) task.resume() } } @@ -114,7 +114,7 @@ private struct ClientInfo { var auth0: StrategyInfo? { return strategies.filter({ $0.name == "auth0" }).first } var oauth2: [StrategyInfo] { return strategies.filter { $0.name != "auth0" && !passwordlessStrategyNames.contains($0.name) && !enterpriseStrategyNames.contains($0.name) } } - + var enterprise: [StrategyInfo] { return strategies.filter { $0.name != "auth0" && !passwordlessStrategyNames.contains($0.name) && enterpriseStrategyNames.contains($0.name) } } let passwordlessStrategyNames = [ @@ -136,7 +136,7 @@ private struct ClientInfo { "custom", "sharepoint", ] - + let enterpriseCredentialAuthNames = [ "waad", "adfs", diff --git a/Lock/Colors.swift b/Lock/Colors.swift index 687f593a9..fa9f6be34 100644 --- a/Lock/Colors.swift +++ b/Lock/Colors.swift @@ -31,11 +31,11 @@ extension UIColor { let hexString: String = string.substring(from: string.characters.index(string.startIndex, offsetBy: 1)) var hexValue: UInt32 = 0 - + guard Scanner(string: hexString).scanHexInt32(&hexValue) else { return defaultColor } - + let divisor = CGFloat(255) let red = CGFloat((hexValue & 0xFF0000) >> 16) / divisor let green = CGFloat((hexValue & 0x00FF00) >> 8) / divisor @@ -43,4 +43,3 @@ extension UIColor { return UIColor(red: red, green: green, blue: blue, alpha: 1) } } - diff --git a/Lock/ConnectionBuildable.swift b/Lock/ConnectionBuildable.swift index 6495b25d4..f7200c2bc 100644 --- a/Lock/ConnectionBuildable.swift +++ b/Lock/ConnectionBuildable.swift @@ -22,7 +22,6 @@ import Foundation - /** * Allows to specify Lock connections */ @@ -55,7 +54,7 @@ public protocol ConnectionBuildable: Connections { - seeAlso: AuthStyle */ mutating func oauth2(name: String, style: AuthStyle) - + /** Adds a new enterprise connection diff --git a/Lock/CredentialView.swift b/Lock/CredentialView.swift index 630f51f20..da4164bb5 100644 --- a/Lock/CredentialView.swift +++ b/Lock/CredentialView.swift @@ -48,7 +48,7 @@ public class CredentialView: UIView, Form { self.passwordField.needsToUpdateState() } - // MARK:- Initialisers + // MARK: - Initialisers public convenience init() { self.init(frame: CGRect.zero) @@ -68,7 +68,7 @@ public class CredentialView: UIView, Form { self.layoutForm() } - // MARK:- Layout + // MARK: - Layout private func layoutForm() { @@ -92,5 +92,5 @@ public class CredentialView: UIView, Form { identifier.type = .email password.type = .password } - + } diff --git a/Lock/DatabaseConstants.swift b/Lock/DatabaseConstants.swift index 58764da91..f7fa741ba 100644 --- a/Lock/DatabaseConstants.swift +++ b/Lock/DatabaseConstants.swift @@ -38,16 +38,15 @@ public enum DatabaseScreen: Int, Equatable { case resetPassword } - public struct DatabaseIdentifierStyle: OptionSet { public let rawValue: Int public init(rawValue: Int) { self.rawValue = rawValue } - + public static let Username = DatabaseIdentifierStyle(rawValue: 1 << 0) public static let Email = DatabaseIdentifierStyle(rawValue: 1 << 1) } -public func ==(lhs: DatabaseScreen, rhs: DatabaseScreen) -> Bool { +public func == (lhs: DatabaseScreen, rhs: DatabaseScreen) -> Bool { return lhs.rawValue == rhs.rawValue } diff --git a/Lock/DatabaseForgotPasswordPresenter.swift b/Lock/DatabaseForgotPasswordPresenter.swift index 699133dbc..175290457 100644 --- a/Lock/DatabaseForgotPasswordPresenter.swift +++ b/Lock/DatabaseForgotPasswordPresenter.swift @@ -33,9 +33,8 @@ class DatabaseForgotPasswordPresenter: Presentable, Loggable { self.database = connections.database! // FIXME: Avoid the force unwrap } - var messagePresenter: MessagePresenter? - + var view: View { let email = self.interactor.validEmail ? self.interactor.email : nil let view = DatabaseForgotPasswordView(email: email) diff --git a/Lock/DatabaseModeSwitcher.swift b/Lock/DatabaseModeSwitcher.swift index df9a3d8e4..707fc77bd 100644 --- a/Lock/DatabaseModeSwitcher.swift +++ b/Lock/DatabaseModeSwitcher.swift @@ -55,7 +55,7 @@ public class DatabaseModeSwitcher: UIView { } } - // MARK:- Initialisers + // MARK: - Initialisers public convenience init() { self.init(frame: CGRect.zero) @@ -71,7 +71,7 @@ public class DatabaseModeSwitcher: UIView { self.layoutSwitcher() } - // MARK:- Layout + // MARK: - Layout private func layoutSwitcher() { let segmented = UISegmentedControl(items: [Mode.login.title, Mode.signup.title]) @@ -113,7 +113,7 @@ public class DatabaseModeSwitcher: UIView { return CGSize(width: UIViewNoIntrinsicMetric, height: 55) } - // MARK:- Internal + // MARK: - Internal func selectedIndex(_ sender: UISegmentedControl) { self.onSelectionChange(self) diff --git a/Lock/DatabaseOnlyView.swift b/Lock/DatabaseOnlyView.swift index 9c6080168..bb43ff210 100644 --- a/Lock/DatabaseOnlyView.swift +++ b/Lock/DatabaseOnlyView.swift @@ -23,7 +23,7 @@ import UIKit class DatabaseOnlyView: UIView, DatabaseView { - + weak var form: Form? weak var secondaryButton: SecondaryButton? weak var primaryButton: PrimaryButton? @@ -33,58 +33,58 @@ class DatabaseOnlyView: UIView, DatabaseView { weak var secondaryStrut: UIView? weak var ssoBar: InfoBarView? weak var spacer: UIView? - + private weak var container: UIStackView? - + let allowedModes: DatabaseMode - + init(allowedModes: DatabaseMode = [.Login, .Signup, .ResetPassword]) { let primaryButton = PrimaryButton() let container = UIStackView() - + self.allowedModes = allowedModes self.primaryButton = primaryButton self.container = container - + super.init(frame: CGRect.zero) - + self.addSubview(container) self.addSubview(primaryButton) - + container.alignment = .fill container.axis = .vertical container.distribution = .equalSpacing container.spacing = 10 - + constraintEqual(anchor: container.leftAnchor, toAnchor: self.leftAnchor) constraintEqual(anchor: container.topAnchor, toAnchor: self.topAnchor) constraintEqual(anchor: container.rightAnchor, toAnchor: self.rightAnchor) constraintEqual(anchor: container.bottomAnchor, toAnchor: primaryButton.topAnchor) container.translatesAutoresizingMaskIntoConstraints = false - + self.layoutSwitcher(allowedModes.contains(.Login) && allowedModes.contains(.Signup)) - + constraintEqual(anchor: primaryButton.leftAnchor, toAnchor: self.leftAnchor) constraintEqual(anchor: primaryButton.rightAnchor, toAnchor: self.rightAnchor) constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: self.bottomAnchor) primaryButton.translatesAutoresizingMaskIntoConstraints = false } - + required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - - // MARK:- Layout - + + // MARK: - Layout + private let switcherIndex = 0 private let formOnlyIndex = 1 private let formBelowSocialIndex = 3 private let separatorIndex = 2 private let socialIndex = 1 - + func showLogin(withIdentifierStyle style: DatabaseIdentifierStyle, identifier: String? = nil, authCollectionView: AuthCollectionView? = nil) { let form = CredentialView() - + let type: InputField.InputType switch style { case [.Email, .Username]: @@ -94,7 +94,7 @@ class DatabaseOnlyView: UIView, DatabaseView { default: type = .email } - + form.identityField.text = identifier form.identityField.type = type form.identityField.returnKey = .next @@ -104,7 +104,7 @@ class DatabaseOnlyView: UIView, DatabaseView { self.layoutSecondaryButton(self.allowedModes.contains(.ResetPassword)) self.form = form } - + func showSignUp(withUsername showUsername: Bool, username: String?, email: String?, authCollectionView: AuthCollectionView? = nil, additionalFields: [CustomTextField]) { let form = SignUpView(additionalFields: additionalFields) form.showUsername = showUsername @@ -119,14 +119,14 @@ class DatabaseOnlyView: UIView, DatabaseView { self.layoutSecondaryButton(true) self.form = form } - + func presentEnterprise() { guard let form = self.form as? CredentialView else { return } let ssoBar = InfoBarView() let viewCount = self.container?.subviews.count ?? 0 let spacer = strutView(withHeight: 125 - CGFloat(viewCount) * 25) - + ssoBar.title = "SINGLE SIGN-ON ENABLED".i18n(key: "com.auth0.lock.enterprise.sso", comment: "SSO Header") ssoBar.setIcon("ic_lock") ssoBar.isHidden = false @@ -136,33 +136,33 @@ class DatabaseOnlyView: UIView, DatabaseView { self.ssoBar = ssoBar self.spacer = spacer - + form.passwordField.isHidden = true form.identityField.nextField = nil form.identityField.returnKey = .done form.identityField.onReturn = form.passwordField.onReturn - + self.switcher?.isHidden = true self.secondaryButton?.isHidden = true } - + func removeEnterprise() { guard let ssoBar = self.ssoBar, let spacer = self.spacer, let form = self.form as? CredentialView else { return } ssoBar.removeFromSuperview() spacer.removeFromSuperview() - + form.passwordField.isHidden = false form.identityField.nextField = form.passwordField form.identityField.returnKey = .next - + self.switcher?.isHidden = false self.secondaryButton?.isHidden = false - + self.ssoBar = nil self.spacer = nil } - + private func layoutSecondaryButton(_ enabled: Bool) { self.secondaryStrut?.removeFromSuperview() self.secondaryButton?.removeFromSuperview() @@ -176,7 +176,7 @@ class DatabaseOnlyView: UIView, DatabaseView { self.container?.addArrangedSubview(view) } } - + private func layoutSwitcher(_ enabled: Bool) { self.container?.arrangedSubviews.first?.removeFromSuperview() if enabled { @@ -188,14 +188,14 @@ class DatabaseOnlyView: UIView, DatabaseView { self.container?.insertArrangedSubview(view, at: switcherIndex) } } - + private func layoutInStack(_ view: UIView, authCollectionView: AuthCollectionView?) { if let current = self.form as? UIView { current.removeFromSuperview() } self.authCollectionView?.removeFromSuperview() self.separator?.removeFromSuperview() - + if let social = authCollectionView { let label = UILabel() label.text = "or".i18n(key: "com.auth0.lock.database.separator", comment: "Social separator") @@ -211,9 +211,9 @@ class DatabaseOnlyView: UIView, DatabaseView { self.container?.insertArrangedSubview(view, at: formOnlyIndex) } } - - // MARK:- Styling - + + // MARK: - Styling + func apply(style: Style) { primaryButton?.apply(style: style) } diff --git a/Lock/DatabasePasswordInteractor.swift b/Lock/DatabasePasswordInteractor.swift index 7b946fa56..3b6755ac3 100644 --- a/Lock/DatabasePasswordInteractor.swift +++ b/Lock/DatabasePasswordInteractor.swift @@ -50,7 +50,7 @@ struct DatabasePasswordInteractor: PasswordRecoverable { func requestEmail(_ callback: @escaping (PasswordRecoverableError?) -> ()) { guard let email = self.email else { return callback(.nonValidInput) } guard let connection = self.connections.database?.name else { return callback(.noDatabaseConnection) } - + self.authentication .resetPassword(email: email, connection: connection) .start { diff --git a/Lock/DatabasePresenter.swift b/Lock/DatabasePresenter.swift index 20e282226..bf637e265 100644 --- a/Lock/DatabasePresenter.swift +++ b/Lock/DatabasePresenter.swift @@ -83,7 +83,7 @@ class DatabasePresenter: Presentable, Loggable { private func showLogin(inView view: DatabaseView, identifier: String?) { self.messagePresenter?.hideCurrent() - let authCollectionView = self.authPresenter?.newViewToEmbed(withInsets: UIEdgeInsetsMake(0, 18, 0, 18), isLogin: true) + let authCollectionView = self.authPresenter?.newViewToEmbed(withInsets: UIEdgeInsets(top: 0, left: 18, bottom: 0, right: 18), isLogin: true) let style = self.database.requiresUsername ? self.options.usernameStyle : [.Email] view.showLogin(withIdentifierStyle: style, identifier: identifier, authCollectionView: authCollectionView) let form = view.form @@ -141,7 +141,7 @@ class DatabasePresenter: Presentable, Loggable { private func showSignup(inView view: DatabaseView, username: String?, email: String?) { self.messagePresenter?.hideCurrent() - let authCollectionView = self.authPresenter?.newViewToEmbed(withInsets: UIEdgeInsetsMake(0, 18, 0, 18), isLogin: false) + let authCollectionView = self.authPresenter?.newViewToEmbed(withInsets: UIEdgeInsets(top: 0, left: 18, bottom: 0, right: 18), isLogin: false) view.showSignUp(withUsername: self.database.requiresUsername, username: username, email: email, authCollectionView: authCollectionView, additionalFields: self.options.customSignupFields) let form = view.form view.form?.onValueChange = self.handleInput diff --git a/Lock/DatabaseView.swift b/Lock/DatabaseView.swift index 5f7c1f4ea..eff155339 100644 --- a/Lock/DatabaseView.swift +++ b/Lock/DatabaseView.swift @@ -35,4 +35,4 @@ protocol DatabaseView: View { func showLogin(withIdentifierStyle style: DatabaseIdentifierStyle, identifier: String?, authCollectionView: AuthCollectionView?) func showSignUp(withUsername showUsername: Bool, username: String?, email: String?, authCollectionView: AuthCollectionView?, additionalFields: [CustomTextField]) -} \ No newline at end of file +} diff --git a/Lock/EnterpriseActiveAuthInteractor.swift b/Lock/EnterpriseActiveAuthInteractor.swift index 21b22459a..f9f8041fd 100644 --- a/Lock/EnterpriseActiveAuthInteractor.swift +++ b/Lock/EnterpriseActiveAuthInteractor.swift @@ -24,7 +24,7 @@ import Foundation import Auth0 struct EnterpriseActiveAuthInteractor: DatabaseAuthenticatable, Loggable { - + var identifier: String? = nil var email: String? = nil diff --git a/Lock/EnterpriseActiveAuthPresenter.swift b/Lock/EnterpriseActiveAuthPresenter.swift index 61e8fb22a..7aba1f49e 100644 --- a/Lock/EnterpriseActiveAuthPresenter.swift +++ b/Lock/EnterpriseActiveAuthPresenter.swift @@ -23,32 +23,32 @@ import Foundation class EnterpriseActiveAuthPresenter: Presentable, Loggable { - + var interactor: EnterpriseActiveAuthInteractor var customLogger: Logger? - + init(interactor: EnterpriseActiveAuthInteractor) { self.interactor = interactor } - + var messagePresenter: MessagePresenter? - + var view: View { var identifier: String? - + if let email = self.interactor.email, self.interactor.validEmail { identifier = email } else if let username = self.interactor.username, self.interactor.validUsername { identifier = username } - + let view = EnterpriseActiveAuthView(identifer: identifier, identifierAttribute: self.interactor.identifierAttribute) let form = view.form view.ssoBar?.title = self.interactor.connection.domains.first - + view.form?.onValueChange = { input in self.messagePresenter?.hideCurrent() - + do { switch input.type { case .email, .username: @@ -64,12 +64,12 @@ class EnterpriseActiveAuthPresenter: Presentable, Loggable { input.showError() } } - + let action = { (button: PrimaryButton) in self.messagePresenter?.hideCurrent() self.logger.info("Enterprise password connection started: \(self.interactor.identifier), \(self.interactor.connection)") let interactor = self.interactor - + button.inProgress = true interactor.login { error in Queue.main.async { @@ -82,10 +82,10 @@ class EnterpriseActiveAuthPresenter: Presentable, Loggable { self.logger.debug("Enterprise connection success") } } - + } } - + view.primaryButton?.onPress = action view.form?.onReturn = {_ in guard let button = view.primaryButton else { return } @@ -93,5 +93,5 @@ class EnterpriseActiveAuthPresenter: Presentable, Loggable { } return view } - + } diff --git a/Lock/EnterpriseActiveAuthView.swift b/Lock/EnterpriseActiveAuthView.swift index c40025493..28ea2db64 100644 --- a/Lock/EnterpriseActiveAuthView.swift +++ b/Lock/EnterpriseActiveAuthView.swift @@ -30,7 +30,7 @@ class EnterpriseActiveAuthView: UIView, View { private weak var container: UIStackView? - init(identifer: String?, identifierAttribute: UserAttribute) { + init(identifer: String?, identifierAttribute:UserAttribute) { let primaryButton = PrimaryButton() let credentialView = CredentialView() let container = UIStackView() diff --git a/Lock/EnterpriseDomain.swift b/Lock/EnterpriseDomain.swift index 40fa1008b..25cd2e6df 100644 --- a/Lock/EnterpriseDomain.swift +++ b/Lock/EnterpriseDomain.swift @@ -27,6 +27,6 @@ protocol HRDAuthenticatable { var validEmail: Bool { get } mutating func updateEmail(_ value: String?) throws - + func login(_ callback: @escaping (OAuth2AuthenticatableError?) -> ()) } diff --git a/Lock/EnterpriseDomainInteractor.swift b/Lock/EnterpriseDomainInteractor.swift index 2515bdbad..db2d4ff5c 100644 --- a/Lock/EnterpriseDomainInteractor.swift +++ b/Lock/EnterpriseDomainInteractor.swift @@ -47,7 +47,7 @@ struct EnterpriseDomainInteractor: HRDAuthenticatable { guard let domain = value?.components(separatedBy: "@").last else { return nil } return connections.filter { $0.domains.contains(domain) }.first } - + mutating func updateEmail(_ value: String?) throws { validEmail = false connection = nil @@ -57,13 +57,13 @@ struct EnterpriseDomainInteractor: HRDAuthenticatable { throw error } validEmail = true - + connection = matchDomain(value) } - + func login(_ callback: @escaping (OAuth2AuthenticatableError?) -> ()) { guard let connection = self.connection else { return callback(.noConnectionAvailable) } authenticator.login(connection.name, callback: callback) } - + } diff --git a/Lock/EnterpriseDomainPresenter.swift b/Lock/EnterpriseDomainPresenter.swift index ef70af8bf..b2a2b86fe 100644 --- a/Lock/EnterpriseDomainPresenter.swift +++ b/Lock/EnterpriseDomainPresenter.swift @@ -44,7 +44,7 @@ class EnterpriseDomainPresenter: Presentable, Loggable { var view: View { let email = self.interactor.validEmail ? self.interactor.email : nil - let authCollectionView = self.authPresenter?.newViewToEmbed(withInsets: UIEdgeInsetsMake(0, 0, 0, 0), isLogin: true) + let authCollectionView = self.authPresenter?.newViewToEmbed(withInsets: UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0), isLogin: true) // Single Enterprise Domain if let enterpriseButton = EnterpriseButton(forConnections: interactor.connections, customStyle: [:], isLogin: true, onAction: { @@ -90,7 +90,7 @@ class EnterpriseDomainPresenter: Presentable, Loggable { if let connection = self.interactor.connection, self.options.enterpriseConnectionUsingActiveAuth.contains(connection.name) { guard self.navigator?.navigate(.enterpriseActiveAuth(connection: connection)) == nil else { return } } - + self.messagePresenter?.hideCurrent() self.logger.info("Enterprise connection started: \(self.interactor.email), \(self.interactor.connection)") let interactor = self.interactor diff --git a/Lock/EnterpriseDomainView.swift b/Lock/EnterpriseDomainView.swift index ccab917d0..ef8b76bca 100644 --- a/Lock/EnterpriseDomainView.swift +++ b/Lock/EnterpriseDomainView.swift @@ -23,30 +23,30 @@ import UIKit class EnterpriseDomainView: UIView, View { - + weak var form: Form? weak var ssoBar: InfoBarView? weak var primaryButton: PrimaryButton? weak var authCollectionView: AuthCollectionView? weak var container: UIStackView? weak var authButton: AuthButton? - + init(email: String?, authCollectionView: AuthCollectionView? = nil) { let primaryButton = PrimaryButton() let domainView = EnterpriseSingleInputView() let container = UIStackView() let ssoBar = InfoBarView() - + self.primaryButton = primaryButton self.form = domainView self.container = container - + super.init(frame: CGRect.zero) - + self.addSubview(ssoBar) self.addSubview(container) self.addSubview(primaryButton) - + ssoBar.title = "SINGLE SIGN-ON ENABLED".i18n(key: "com.auth0.lock.enterprise.sso", comment: "SSO Header") ssoBar.setIcon("ic_lock") ssoBar.isHidden = true @@ -55,7 +55,7 @@ class EnterpriseDomainView: UIView, View { container.axis = .vertical container.distribution = .equalSpacing container.spacing = 5 - + container.addArrangedSubview(strutView(withHeight: 25)) if let authCollectionView = authCollectionView { self.authCollectionView = authCollectionView @@ -69,7 +69,7 @@ class EnterpriseDomainView: UIView, View { } container.addArrangedSubview(domainView) container.addArrangedSubview(strutView()) - + constraintEqual(anchor: ssoBar.topAnchor, toAnchor: self.topAnchor) constraintEqual(anchor: ssoBar.leftAnchor, toAnchor: self.leftAnchor, constant: 0) constraintEqual(anchor: ssoBar.rightAnchor, toAnchor: self.rightAnchor, constant: 0) @@ -81,16 +81,16 @@ class EnterpriseDomainView: UIView, View { constraintEqual(anchor: container.rightAnchor, toAnchor: self.rightAnchor, constant: -20) constraintEqual(anchor: container.bottomAnchor, toAnchor: primaryButton.topAnchor) container.translatesAutoresizingMaskIntoConstraints = false - + constraintEqual(anchor: primaryButton.leftAnchor, toAnchor: self.leftAnchor) constraintEqual(anchor: primaryButton.rightAnchor, toAnchor: self.rightAnchor) constraintEqual(anchor: primaryButton.bottomAnchor, toAnchor: self.bottomAnchor) primaryButton.translatesAutoresizingMaskIntoConstraints = false - + domainView.type = .email domainView.returnKey = .done domainView.value = email - + } init(authButton: AuthButton, authCollectionView: AuthCollectionView? = nil) { @@ -131,11 +131,11 @@ class EnterpriseDomainView: UIView, View { required init?(coder aDecoder: NSCoder) { fatalError("init(coder:) has not been implemented") } - + func apply(style: Style) { self.primaryButton?.apply(style: style) } - + } private func strutView(withHeight height: CGFloat = 50) -> UIView { @@ -146,7 +146,7 @@ private func strutView(withHeight height: CGFloat = 50) -> UIView { } public class EnterpriseSingleInputView : SingleInputView { - + public override var intrinsicContentSize : CGSize { return CGSize(width: UIViewNoIntrinsicMetric, height: 50) } diff --git a/Lock/Form.swift b/Lock/Form.swift index da61be8a6..ef7a86917 100644 --- a/Lock/Form.swift +++ b/Lock/Form.swift @@ -26,4 +26,4 @@ import Foundation var onValueChange: (InputField) -> () { get set } var onReturn: (InputField) -> () { get set } func needsToUpdateState() -} \ No newline at end of file +} diff --git a/Lock/HeaderView.swift b/Lock/HeaderView.swift index 2fc820cea..dc1dfc83d 100644 --- a/Lock/HeaderView.swift +++ b/Lock/HeaderView.swift @@ -195,7 +195,7 @@ public class HeaderView: UIView { } } - // MARK:- Blur + // MARK: - Blur private var canBlur: Bool { return self.blurred && !UIAccessibilityIsReduceTransparencyEnabled() @@ -231,7 +231,7 @@ public class HeaderView: UIView { maskView.contentMode = .scaleToFill maskView.image = image(named: "ic_auth0", compatibleWithTraitCollection: self.traitCollection)?.withRenderingMode(.alwaysTemplate) maskView.tintColor = self.maskColor - + self.maskImageView = maskView self.blurView = blurView } diff --git a/Lock/InfoBarView.swift b/Lock/InfoBarView.swift index 45f72f175..58492ff55 100644 --- a/Lock/InfoBarView.swift +++ b/Lock/InfoBarView.swift @@ -37,7 +37,7 @@ public class InfoBarView: UIView { self.setNeedsUpdateConstraints() } } - + public convenience init() { self.init(frame: CGRect.zero) } @@ -70,13 +70,13 @@ public class InfoBarView: UIView { constraintEqual(anchor: titleView.centerXAnchor, toAnchor: container.centerXAnchor) constraintEqual(anchor: titleView.centerYAnchor, toAnchor: container.centerYAnchor) titleView.translatesAutoresizingMaskIntoConstraints = false - + constraintEqual(anchor: iconView.rightAnchor, toAnchor: titleView.leftAnchor, constant: -5) constraintEqual(anchor: iconView.bottomAnchor, toAnchor: titleView.bottomAnchor, constant: -1) iconView.translatesAutoresizingMaskIntoConstraints = false - + container.backgroundColor = UIColor(red:0.97, green:0.97, blue:0.97, alpha:1.0) - + titleView.font = UIFont.systemFont(ofSize: 17) titleView.textColor = UIColor(red:0.45, green:0.45, blue:0.45, alpha:1.0) @@ -85,7 +85,7 @@ public class InfoBarView: UIView { self.clipsToBounds = true } - + func setIcon(_ name: String) { self.iconView?.image = image(named: name) self.iconView?.tintColor = UIColor ( red: 0.5725, green: 0.5804, blue: 0.5843, alpha: 1.0 ) @@ -95,5 +95,4 @@ public class InfoBarView: UIView { return CGSize(width: UIViewNoIntrinsicMetric, height: 35) } - } diff --git a/Lock/InputField.swift b/Lock/InputField.swift index 1d96ac862..d1575913b 100644 --- a/Lock/InputField.swift +++ b/Lock/InputField.swift @@ -71,7 +71,7 @@ public class InputField: UIView, UITextFieldDelegate { var onReturn: (InputField) -> () = {_ in} - // MARK:- Initialisers + // MARK: - Initialisers public convenience init() { self.init(frame: CGRect.zero) @@ -87,7 +87,7 @@ public class InputField: UIView, UITextFieldDelegate { self.layoutField() } - // MARK:- Error + // MARK: - Error func showError(_ message: String? = nil, noDelay: Bool = false) { self.state = .invalid(message) @@ -111,7 +111,7 @@ public class InputField: UIView, UITextFieldDelegate { } } - // MARK:- Layout + // MARK: - Layout private func layoutField() { let container = UIView() @@ -183,7 +183,7 @@ public class InputField: UIView, UITextFieldDelegate { return CGSize(width: 230, height: 50) } - // MARK:- Internal + // MARK: - Internal enum State { case valid @@ -235,7 +235,7 @@ public class InputField: UIView, UITextFieldDelegate { self.onTextChange(self) } - // MARK:- Types + // MARK: - Types public enum InputType { case email case username diff --git a/Lock/Layout.swift b/Lock/Layout.swift index aa663d9df..7813110b6 100644 --- a/Lock/Layout.swift +++ b/Lock/Layout.swift @@ -22,7 +22,7 @@ import Foundation -// MARK:- NSLayoutXAxisAnchor +// MARK: - NSLayoutXAxisAnchor @discardableResult func constraintEqual>(anchor: C, toAnchor anotherAnchor: C, constant: CGFloat? = nil, priority: UILayoutPriority = UILayoutPriorityRequired) -> NSLayoutConstraint { let constraint: NSLayoutConstraint if let value = constant { @@ -47,7 +47,7 @@ import Foundation return constraint } -// MARK:- NSLayoutYAxisAnchor +// MARK: - NSLayoutYAxisAnchor @discardableResult func constraintEqual>(anchor: C, toAnchor anotherAnchor: C, constant: CGFloat? = nil, priority: UILayoutPriority = UILayoutPriorityRequired) -> NSLayoutConstraint { let constraint: NSLayoutConstraint if let value = constant { @@ -72,7 +72,7 @@ import Foundation return constraint } -// MARK:- NSLayoutDimension +// MARK: - NSLayoutDimension @discardableResult func constraintEqual>(anchor: C, toAnchor anotherAnchor: C, constant: CGFloat? = nil, priority: UILayoutPriority = UILayoutPriorityRequired) -> NSLayoutConstraint { let constraint: NSLayoutConstraint if let value = constant { @@ -97,7 +97,7 @@ import Foundation return constraint } -// MARK:- NSLayoutDimension +// MARK: - NSLayoutDimension @discardableResult func dimension(dimension: NSLayoutDimension, withValue value: CGFloat) -> NSLayoutConstraint { let constraint = dimension.constraint(equalToConstant: value) constraint.isActive = true diff --git a/Lock/LazyImage.swift b/Lock/LazyImage.swift index 2b787db40..b5b7ac835 100644 --- a/Lock/LazyImage.swift +++ b/Lock/LazyImage.swift @@ -53,6 +53,6 @@ public struct LazyImage: Equatable { } } -public func ==(lhs: LazyImage, rhs: LazyImage) -> Bool { +public func == (lhs: LazyImage, rhs: LazyImage) -> Bool { return lhs.name == rhs.name && lhs.bundle == rhs.bundle } diff --git a/Lock/LoadingView.swift b/Lock/LoadingView.swift index d6236416b..7256195c7 100644 --- a/Lock/LoadingView.swift +++ b/Lock/LoadingView.swift @@ -31,7 +31,7 @@ class LoadingView: UIView, View { return self.indicator?.isAnimating ?? false } set { - Queue.main.async { + Queue.main.async { if newValue { self.indicator?.startAnimating() } else { @@ -41,7 +41,7 @@ class LoadingView: UIView, View { } } - // MARK:- Initialisers + // MARK: - Initialisers init() { super.init(frame: CGRect.zero) @@ -62,7 +62,6 @@ class LoadingView: UIView, View { fatalError("init(coder:) has not been implemented") } - func apply(style: Style) { self.indicator?.color = style.disabledTextColor } diff --git a/Lock/LockOptions.swift b/Lock/LockOptions.swift index e98e7a6a1..918fb41ed 100644 --- a/Lock/LockOptions.swift +++ b/Lock/LockOptions.swift @@ -36,7 +36,7 @@ struct LockOptions: OptionBuildable { var initialScreen: DatabaseScreen = .login var usernameStyle: DatabaseIdentifierStyle = [.Username, .Email] var customSignupFields: [CustomTextField] = [] - + // Enterprise var activeDirectoryEmailAsUsername: Bool = false var enterpriseConnectionUsingActiveAuth: [String] = [] diff --git a/Lock/LockViewController.swift b/Lock/LockViewController.swift index 38f8148f5..719cfaf24 100644 --- a/Lock/LockViewController.swift +++ b/Lock/LockViewController.swift @@ -31,7 +31,6 @@ public class LockViewController: UIViewController, MessagePresenter { var keyboard: Bool = false var routes: Routes = Routes() - var anchorConstraint: NSLayoutConstraint? var router: Router! @@ -106,7 +105,7 @@ public class LockViewController: UIViewController, MessagePresenter { self.view.layoutIfNeeded() } - // MARK:- MessagePresenter + // MARK: - MessagePresenter func showError(_ error: LocalizableError) { guard error.userVisible else { return } @@ -139,7 +138,7 @@ public class LockViewController: UIViewController, MessagePresenter { Queue.main.after(4) { [weak view] in view?.removeFromSuperview() } } - // MARK:- Keyboard + // MARK: - Keyboard func keyboardWasShown(_ notification: Notification) { guard diff --git a/Lock/Logger.swift b/Lock/Logger.swift index 57636179a..4d5428438 100644 --- a/Lock/Logger.swift +++ b/Lock/Logger.swift @@ -55,7 +55,7 @@ class Logger { } } -// MARK:- Level +// MARK: - Level public enum LoggerLevel: Int { case off = 0 @@ -84,11 +84,11 @@ public enum LoggerLevel: Int { } } -func >=(lhs: LoggerLevel, rhs: LoggerLevel) -> Bool { +func >= (lhs: LoggerLevel, rhs: LoggerLevel) -> Bool { return lhs.rawValue >= rhs.rawValue } -// MARK:- Loggable +// MARK: - Loggable protocol Loggable { } @@ -98,7 +98,7 @@ extension Loggable { } } -// MARK:- LoggerOutput +// MARK: - LoggerOutput public protocol LoggerOutput { func message(_ message: String, level: LoggerLevel, filename: String, line: Int) @@ -112,7 +112,7 @@ struct DefaultLoggerOutput: LoggerOutput { var trace: (String, LoggerLevel, String) -> () = { print("\($1.label) | \($0) - \($2)") } private func heading(forFile file: String, line: Int) -> String { - let filename = URL(fileURLWithPath: file).lastPathComponent + let filename = URL(fileURLWithPath: file).lastPathComponent return "\(filename):\(line)" } } diff --git a/Lock/MessagePresenter.swift b/Lock/MessagePresenter.swift index 86b3ff09f..863f52127 100644 --- a/Lock/MessagePresenter.swift +++ b/Lock/MessagePresenter.swift @@ -32,5 +32,5 @@ protocol MessagePresenter { func showError(_ error: LocalizableError) func showSuccess(_ message: String) func hideCurrent() - + } diff --git a/Lock/MessageView.swift b/Lock/MessageView.swift index 123bad5e6..0b8e18804 100644 --- a/Lock/MessageView.swift +++ b/Lock/MessageView.swift @@ -73,7 +73,7 @@ public class MessageView: UIView { self.init(frame: CGRect.zero) } - // MARK:- Layout + // MARK: - Layout private func layoutMessage() { let guide = UILayoutGuide() diff --git a/Lock/OfflineConnections.swift b/Lock/OfflineConnections.swift index 16421138c..5386a3c6e 100644 --- a/Lock/OfflineConnections.swift +++ b/Lock/OfflineConnections.swift @@ -41,7 +41,7 @@ struct OfflineConnections: ConnectionBuildable { let social = SocialConnection(name: name, style: style) self.oauth2.append(social) } - + mutating func enterprise(name: String, domains: [String], style: AuthStyle) { let enterprise = EnterpriseConnection(name: name, domains: domains, style: style) self.enterprise.append(enterprise) diff --git a/Lock/OptionBuildable.swift b/Lock/OptionBuildable.swift index fef7b2b85..fd75f5573 100644 --- a/Lock/OptionBuildable.swift +++ b/Lock/OptionBuildable.swift @@ -66,10 +66,10 @@ public protocol OptionBuildable: Options { /// Additional fields showed for Database Sign Up. By default the list is empty var customSignupFields: [CustomTextField] { get set } - + /// Should enterprise credential auth require email instead of username. By default is false var activeDirectoryEmailAsUsername: Bool { get set } - + /// Should an enterprise connection use credentials instead of WebAuth. By default enterprise connections use WebAuth var enterpriseConnectionUsingActiveAuth: [String] { get set } } @@ -105,5 +105,5 @@ public extension OptionBuildable { self.privacyPolicyURL = url } } - + } diff --git a/Lock/Options.swift b/Lock/Options.swift index bea4a788e..4e98c2621 100644 --- a/Lock/Options.swift +++ b/Lock/Options.swift @@ -27,7 +27,7 @@ public protocol Options { var termsOfServiceURL: URL { get } var privacyPolicyURL: URL { get } - + var logLevel: LoggerLevel { get } var loggerOutput: LoggerOutput? { get } var logHttpRequest: Bool { get } @@ -38,7 +38,7 @@ public protocol Options { var initialScreen: DatabaseScreen { get } var usernameStyle: DatabaseIdentifierStyle { get } var customSignupFields: [CustomTextField] { get } - + // Enterprise var activeDirectoryEmailAsUsername: Bool { get } var enterpriseConnectionUsingActiveAuth: [String] { get } diff --git a/Lock/Presentable.swift b/Lock/Presentable.swift index 5f1c67593..b7da74fa9 100644 --- a/Lock/Presentable.swift +++ b/Lock/Presentable.swift @@ -25,4 +25,4 @@ import Foundation protocol Presentable { var view: View { get } var messagePresenter: MessagePresenter? { get set } -} \ No newline at end of file +} diff --git a/Lock/Routes.swift b/Lock/Routes.swift index add163d9a..ee4027f49 100644 --- a/Lock/Routes.swift +++ b/Lock/Routes.swift @@ -51,7 +51,7 @@ enum Route: Equatable { case enterpriseActiveAuth(connection: EnterpriseConnection) } -func ==(lhs: Route, rhs: Route) -> Bool { +func == (lhs: Route, rhs: Route) -> Bool { switch((lhs, rhs)) { case (.root, .root), (.forgotPassword, .forgotPassword), (.multifactor, .multifactor): return true diff --git a/Lock/SecondaryButton.swift b/Lock/SecondaryButton.swift index 0a268acc6..25b460fea 100644 --- a/Lock/SecondaryButton.swift +++ b/Lock/SecondaryButton.swift @@ -43,7 +43,7 @@ public class SecondaryButton: UIView { } } - // MARK:- Initialisers + // MARK: - Initialisers public convenience init() { self.init(frame: CGRect.zero) } @@ -58,7 +58,7 @@ public class SecondaryButton: UIView { self.layoutButton() } - // MARK:- Layout + // MARK: - Layout private func layoutButton() { let button = UIButton(type: .system) @@ -83,7 +83,7 @@ public class SecondaryButton: UIView { public override var intrinsicContentSize : CGSize { return CGSize(width: UIViewNoIntrinsicMetric, height: 76) } - + func pressed(_ sender: Any) { self.onPress(self) } diff --git a/Lock/SignUpView.swift b/Lock/SignUpView.swift index 6cf495d7d..fd13e6cd1 100644 --- a/Lock/SignUpView.swift +++ b/Lock/SignUpView.swift @@ -64,7 +64,7 @@ public class SignUpView: UIView, Form { .forEach { $0.needsToUpdateState() } } - // MARK:- Initialisers + // MARK: - Initialisers public init(additionalFields: [CustomTextField]) { self.emailField = inputField(withType: .email) @@ -92,7 +92,7 @@ public class SignUpView: UIView, Form { self.layoutForm() } - // MARK:- Layout + // MARK: - Layout private func layoutForm() { @@ -122,7 +122,6 @@ public class SignUpView: UIView, Form { } } - private func inputField(withType type: InputField.InputType) -> InputField { let field = InputField() field.type = type diff --git a/Lock/SingleInputView.swift b/Lock/SingleInputView.swift index 8a1629e5c..1b42e81e3 100644 --- a/Lock/SingleInputView.swift +++ b/Lock/SingleInputView.swift @@ -86,7 +86,7 @@ public class SingleInputView: UIView, Form { self.inputField.needsToUpdateState() } - // MARK:- Initialisers + // MARK: - Initialisers required override public init(frame: CGRect) { self.inputField = InputField() @@ -105,7 +105,7 @@ public class SingleInputView: UIView, Form { self.init(frame: CGRect.zero) } - // MARK:- Layout + // MARK: - Layout private func layoutForm() { self.addSubview(self.stackView) diff --git a/Lock/Style.swift b/Lock/Style.swift index 0afe7f6de..5392eea61 100644 --- a/Lock/Style.swift +++ b/Lock/Style.swift @@ -59,8 +59,8 @@ public struct Style { /// OAuth2 custom connection styles by mapping a connection name with an `AuthStyle` public var oauth2: [String: AuthStyle] = [:] - - var headerMask: UIImage? { + + var headerMask: UIImage? { let image = self.logo.image(compatibleWithTraits: nil) if Style.Auth0.logo == self.logo { return image?.withRenderingMode(.alwaysTemplate) @@ -91,7 +91,6 @@ public struct Style { static let Auth0 = Style() } - protocol Stylable { func apply(style: Style) } diff --git a/Lock/UserAttribute.swift b/Lock/UserAttribute.swift index aabb5e884..00f694481 100644 --- a/Lock/UserAttribute.swift +++ b/Lock/UserAttribute.swift @@ -29,4 +29,3 @@ enum UserAttribute { case emailOrUsername case custom(name: String) } - diff --git a/Lock/View.swift b/Lock/View.swift index 2e61bd568..de2020b23 100644 --- a/Lock/View.swift +++ b/Lock/View.swift @@ -45,4 +45,4 @@ extension View where Self: UIView { func remove() { self.removeFromSuperview() } -} \ No newline at end of file +} diff --git a/LockTests/Utils/NetworkStub.swift b/LockTests/Utils/NetworkStub.swift index 46090902b..09f726392 100644 --- a/LockTests/Utils/NetworkStub.swift +++ b/LockTests/Utils/NetworkStub.swift @@ -23,7 +23,7 @@ import Foundation import OHHTTPStubs -// MARK:- Request Matchers +// MARK: - Request Matchers func databaseLogin(identifier: String, password: String, code: String? = nil, connection: String) -> OHHTTPStubsTestBlock { var parameters = ["username": identifier, "password": password, "connection": connection] @@ -43,7 +43,7 @@ func databaseForgotPassword(email: String, connection: String) -> OHHTTPStubsTes return isHost("samples.auth0.com") && isMethodPOST() && isPath("/dbconnections/change_password") && hasAtLeast(["email": email, "connection": connection]) } -// MARK:- Internal Matchers +// MARK: - Internal Matchers extension URLRequest { var a0_payload: [String: Any]? { @@ -108,7 +108,7 @@ func isCDN(forClientId clientId: String) -> OHHTTPStubsTestBlock { return isMethodGET() && isHost("cdn.auth0.com") && isPath("/client/\(clientId).js") } -// MARK:- Response Stubs +// MARK: - Response Stubs struct Auth0Stubs { static func cleanAll() { OHHTTPStubs.removeAllStubs() }