From e972ff378d3441e3560049c52a922cc683e430cd Mon Sep 17 00:00:00 2001 From: Steve Lind Date: Fri, 17 Dec 2021 11:42:05 -0800 Subject: [PATCH] Add SwiftLint, fix swiftlint issues --- .../Contents.swift | 12 ++++++++++++ .../Home.xcplaygroundpage/Contents.swift | 13 +++++++++++++ OktaLogger.xcodeproj/project.pbxproj | 19 +++++++++++++++++++ .../AppCenterLogger/AppCenterLogger.swift | 1 + .../DDLogFileManagerCustomName.swift | 1 + .../LumberjackLoggerDelegate.swift | 1 + .../OktaLoggerFileLogFormatter.swift | 6 ------ .../FileLoggers/OktaLoggerFileLogger.swift | 3 ++- .../OktaLoggerFileLoggerConfig.swift | 2 ++ .../OktaLoggerFirebaseCrashlyticsLogger.swift | 9 +++++---- .../OktaLoggerInstabugLogger.swift | 6 ++---- OktaLogger/OktaLogger.swift | 3 ++- OktaLogger/OktaLoggerDestination.swift | 3 ++- OktaLoggerTests/Helpers/FileTestsHelper.swift | 3 ++- ...aLoggerFileLoggerMultithreadingTests.swift | 2 +- .../OktaLoggerFirebaseLoggerTests.swift | 6 +++--- 16 files changed, 68 insertions(+), 22 deletions(-) diff --git a/OktaLogger.playground/Pages/FileLogger.xcplaygroundpage/Contents.swift b/OktaLogger.playground/Pages/FileLogger.xcplaygroundpage/Contents.swift index 58cff82..a43a87c 100644 --- a/OktaLogger.playground/Pages/FileLogger.xcplaygroundpage/Contents.swift +++ b/OktaLogger.playground/Pages/FileLogger.xcplaygroundpage/Contents.swift @@ -1,3 +1,15 @@ +/* + * Copyright (c) 2020-Present, Okta, Inc. and/or its affiliates. All rights reserved. + * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and limitations under the License. + */ + import UIKit import OktaLogger diff --git a/OktaLogger.playground/Pages/Home.xcplaygroundpage/Contents.swift b/OktaLogger.playground/Pages/Home.xcplaygroundpage/Contents.swift index fee069f..85f5046 100644 --- a/OktaLogger.playground/Pages/Home.xcplaygroundpage/Contents.swift +++ b/OktaLogger.playground/Pages/Home.xcplaygroundpage/Contents.swift @@ -1,2 +1,15 @@ +/* + * Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved. + * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") + * + * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and limitations under the License. + */ + + //: # OktaLogger Documentation //: - [How to Use a File Logger?](FileLogger) diff --git a/OktaLogger.xcodeproj/project.pbxproj b/OktaLogger.xcodeproj/project.pbxproj index ecfcfa6..2a36b0e 100644 --- a/OktaLogger.xcodeproj/project.pbxproj +++ b/OktaLogger.xcodeproj/project.pbxproj @@ -367,6 +367,7 @@ D5C824D12469DBF1005CF747 /* Frameworks */, D5C824D22469DBF1005CF747 /* Resources */, 80DDE78E24B962C900D0E2F3 /* Embed Frameworks */, + 7B0C4EE7276D1DAC0033BDC6 /* SwiftLint */, ); buildRules = ( ); @@ -574,6 +575,24 @@ shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n"; showEnvVarsInLog = 0; }; + 7B0C4EE7276D1DAC0033BDC6 /* SwiftLint */ = { + isa = PBXShellScriptBuildPhase; + buildActionMask = 2147483647; + files = ( + ); + inputFileListPaths = ( + ); + inputPaths = ( + ); + name = SwiftLint; + outputFileListPaths = ( + ); + outputPaths = ( + ); + runOnlyForDeploymentPostprocessing = 0; + shellPath = /bin/sh; + shellScript = "\"${PODS_ROOT}/SwiftLint/swiftlint\" --config \"${PROJECT_DIR}/.swiftlint.yml\"\n"; + }; 9ECAD1E0171C5273C443BE35 /* [CP] Embed Pods Frameworks */ = { isa = PBXShellScriptBuildPhase; buildActionMask = 2147483647; diff --git a/OktaLogger/AppCenterLogger/AppCenterLogger.swift b/OktaLogger/AppCenterLogger/AppCenterLogger.swift index a707601..3098eed 100644 --- a/OktaLogger/AppCenterLogger/AppCenterLogger.swift +++ b/OktaLogger/AppCenterLogger/AppCenterLogger.swift @@ -9,6 +9,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import AppCenterAnalytics /** diff --git a/OktaLogger/FileLoggers/DDLogFileManagerCustomName.swift b/OktaLogger/FileLoggers/DDLogFileManagerCustomName.swift index 730a065..bb3d96d 100644 --- a/OktaLogger/FileLoggers/DDLogFileManagerCustomName.swift +++ b/OktaLogger/FileLoggers/DDLogFileManagerCustomName.swift @@ -9,6 +9,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import Foundation import CocoaLumberjack diff --git a/OktaLogger/FileLoggers/LumberjackLoggerDelegate.swift b/OktaLogger/FileLoggers/LumberjackLoggerDelegate.swift index 54f073e..38501b9 100644 --- a/OktaLogger/FileLoggers/LumberjackLoggerDelegate.swift +++ b/OktaLogger/FileLoggers/LumberjackLoggerDelegate.swift @@ -9,6 +9,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import CocoaLumberjack class LumberjackLoggerDelegate: FileLoggerDelegate { diff --git a/OktaLogger/FileLoggers/OktaLoggerFileLogFormatter.swift b/OktaLogger/FileLoggers/OktaLoggerFileLogFormatter.swift index a95c415..51081b7 100644 --- a/OktaLogger/FileLoggers/OktaLoggerFileLogFormatter.swift +++ b/OktaLogger/FileLoggers/OktaLoggerFileLogFormatter.swift @@ -9,12 +9,6 @@ * * See the License for the specific language governing permissions and limitations under the License. */ -// -// OktaLoggerFileLogFormatter.swift -// OktaLogger -// -// Created by Borys Kasianenko on 1/25/21. -// import Foundation import CocoaLumberjack diff --git a/OktaLogger/FileLoggers/OktaLoggerFileLogger.swift b/OktaLogger/FileLoggers/OktaLoggerFileLogger.swift index 366acf7..3128d32 100644 --- a/OktaLogger/FileLoggers/OktaLoggerFileLogger.swift +++ b/OktaLogger/FileLoggers/OktaLoggerFileLogger.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-Present, Okta, Inc. and/or its affiliates. All rights reserved. + * Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved. * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") * * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. @@ -9,6 +9,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import Foundation @objc diff --git a/OktaLogger/FileLoggers/OktaLoggerFileLoggerConfig.swift b/OktaLogger/FileLoggers/OktaLoggerFileLoggerConfig.swift index 5273bbd..817e65d 100644 --- a/OktaLogger/FileLoggers/OktaLoggerFileLoggerConfig.swift +++ b/OktaLogger/FileLoggers/OktaLoggerFileLoggerConfig.swift @@ -9,7 +9,9 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import Foundation + @objc public class OktaLoggerFileLoggerConfig: NSObject { diff --git a/OktaLogger/FirebaseCrashlyticsLogger/OktaLoggerFirebaseCrashlyticsLogger.swift b/OktaLogger/FirebaseCrashlyticsLogger/OktaLoggerFirebaseCrashlyticsLogger.swift index 86d057a..5cfbfd7 100644 --- a/OktaLogger/FirebaseCrashlyticsLogger/OktaLoggerFirebaseCrashlyticsLogger.swift +++ b/OktaLogger/FirebaseCrashlyticsLogger/OktaLoggerFirebaseCrashlyticsLogger.swift @@ -9,6 +9,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import FirebaseCrashlytics /** @@ -91,7 +92,7 @@ open class OktaLoggerFirebaseCrashlyticsLogger: OktaLoggerDestinationBase { let normalizedEventName = eventName.lowercased().replacingOccurrences(of: " ", with: "-") return "\(identifier).\(normalizedEventName)" } - + class func createUserInfoDict(level: OktaLoggerLogLevel, eventName: String, message: String?, @@ -108,19 +109,19 @@ open class OktaLoggerFirebaseCrashlyticsLogger: OktaLoggerDestinationBase { "line": line, "function": funcName ] - + // merge destination-level properties into userInfo (high priority) if let defaultProperties = defaultProperties as? [String: Any], !defaultProperties.isEmpty { userInfo.merge(defaultProperties) { (_, last) in last } } - + // merge log-level properties into userInfo (highest priority) if let properties = properties as? [String: Any], !properties.isEmpty { userInfo.merge(properties) { (_, last) in last } } - + return userInfo } } diff --git a/OktaLogger/InstabugLogger/OktaLoggerInstabugLogger.swift b/OktaLogger/InstabugLogger/OktaLoggerInstabugLogger.swift index 018a0dc..bc0f3bc 100644 --- a/OktaLogger/InstabugLogger/OktaLoggerInstabugLogger.swift +++ b/OktaLogger/InstabugLogger/OktaLoggerInstabugLogger.swift @@ -12,9 +12,7 @@ import Instabug -/** - Concrete logging class for Instabug. - */ +/// Concrete logging destination for Instabug open class OktaLoggerInstabugLogger: OktaLoggerDestinationBase { override open func log(level: OktaLoggerLogLevel, eventName: String, message: String?, properties: [AnyHashable: Any]?, file: String, line: NSNumber, funcName: String) { @@ -47,7 +45,7 @@ open class OktaLoggerInstabugLogger: OktaLoggerDestinationBase { } } - open override func stringValue(level: OktaLoggerLogLevel, eventName: String, message: String?, file: String, line: NSNumber, funcName: String) -> String { + override open func stringValue(level: OktaLoggerLogLevel, eventName: String, message: String?, file: String, line: NSNumber, funcName: String) -> String { let fileLogString = file.split(separator: "/").last ?? "" let messageLogString: String = { guard let message = message else { diff --git a/OktaLogger/OktaLogger.swift b/OktaLogger/OktaLogger.swift index 1893b17..5f14a22 100644 --- a/OktaLogger/OktaLogger.swift +++ b/OktaLogger/OktaLogger.swift @@ -9,6 +9,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import Foundation /** @@ -136,7 +137,7 @@ open class OktaLogger: NSObject, OktaLoggerProtocol { self.loggingDestinations = destinationDict } - public convenience override init() { + override public convenience init() { self.init(destinations: []) } diff --git a/OktaLogger/OktaLoggerDestination.swift b/OktaLogger/OktaLoggerDestination.swift index 6e805e5..d589ddb 100644 --- a/OktaLogger/OktaLoggerDestination.swift +++ b/OktaLogger/OktaLoggerDestination.swift @@ -1,5 +1,5 @@ /* - * Copyright (c) 2020-Present, Okta, Inc. and/or its affiliates. All rights reserved. + * Copyright (c) 2021-Present, Okta, Inc. and/or its affiliates. All rights reserved. * The Okta software accompanied by this notice is provided pursuant to the Apache License, Version 2.0 (the "License.") * * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0. @@ -9,6 +9,7 @@ * * See the License for the specific language governing permissions and limitations under the License. */ + import Foundation /** diff --git a/OktaLoggerTests/Helpers/FileTestsHelper.swift b/OktaLoggerTests/Helpers/FileTestsHelper.swift index bd36169..7dd726a 100644 --- a/OktaLoggerTests/Helpers/FileTestsHelper.swift +++ b/OktaLoggerTests/Helpers/FileTestsHelper.swift @@ -53,7 +53,8 @@ class FileTestsHelper { try? FileManager.default.removeItem(at: FileTestsHelper.testLogsFolder) } - static private var testLogsFolder: URL { + // swiftlint:disable force_unwrapping + private static var testLogsFolder: URL { return FileManager.default.urls(for: .cachesDirectory, in: .userDomainMask).first! .appendingPathComponent("TestLogs", isDirectory: true) } diff --git a/OktaLoggerTests/OktaLoggerFileLoggerMultithreadingTests.swift b/OktaLoggerTests/OktaLoggerFileLoggerMultithreadingTests.swift index 548775c..1e977b5 100644 --- a/OktaLoggerTests/OktaLoggerFileLoggerMultithreadingTests.swift +++ b/OktaLoggerTests/OktaLoggerFileLoggerMultithreadingTests.swift @@ -70,7 +70,7 @@ class OktaLoggerFileLoggerMultithreadingTests: XCTestCase { } wait(for: [testFinishExpectation], timeout: defaultTimeout) - + let purgeExpectation = expectation(description: "Purge logs from main thread") lumberjackDelegate.purgeLogs() DispatchQueue.main.async { diff --git a/OktaLoggerTests/OktaLoggerFirebaseLoggerTests.swift b/OktaLoggerTests/OktaLoggerFirebaseLoggerTests.swift index 603d81a..ceaacef 100644 --- a/OktaLoggerTests/OktaLoggerFirebaseLoggerTests.swift +++ b/OktaLoggerTests/OktaLoggerFirebaseLoggerTests.swift @@ -13,7 +13,7 @@ import XCTest @testable import OktaLogger class OktaLoggerFirebaseLoggerTests: XCTestCase { - + /// Verify that the userInfo dict is created as expected /// defaultProperties and logged properties should be merged into the userInfo dict in correct priority func testUserInfoMerge() { @@ -22,7 +22,7 @@ class OktaLoggerFirebaseLoggerTests: XCTestCase { let pushToken = UUID().uuidString let properties = [ "pushToken": pushToken, - "override" : "SUCCESS" + "override": "SUCCESS" ] let appInstanceId = UUID().uuidString let file = UUID().uuidString @@ -41,7 +41,7 @@ class OktaLoggerFirebaseLoggerTests: XCTestCase { file: file, line: line, funcName: funcName) - + XCTAssertEqual(userInfo["eventName"] as? String, eventName) XCTAssertEqual(userInfo["message"] as? String, message) XCTAssertEqual(userInfo["pushToken"] as? String, pushToken)