Skip to content

Commit

Permalink
Add SwiftLint, fix swiftlint issues
Browse files Browse the repository at this point in the history
  • Loading branch information
stevelind-okta committed Dec 22, 2021
1 parent ede1182 commit e972ff3
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 22 deletions.
Original file line number Diff line number Diff line change
@@ -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

Expand Down
13 changes: 13 additions & 0 deletions OktaLogger.playground/Pages/Home.xcplaygroundpage/Contents.swift
Original file line number Diff line number Diff line change
@@ -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)
19 changes: 19 additions & 0 deletions OktaLogger.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@
D5C824D12469DBF1005CF747 /* Frameworks */,
D5C824D22469DBF1005CF747 /* Resources */,
80DDE78E24B962C900D0E2F3 /* Embed Frameworks */,
7B0C4EE7276D1DAC0033BDC6 /* SwiftLint */,
);
buildRules = (
);
Expand Down Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions OktaLogger/AppCenterLogger/AppCenterLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import AppCenterAnalytics

/**
Expand Down
1 change: 1 addition & 0 deletions OktaLogger/FileLoggers/DDLogFileManagerCustomName.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import Foundation
import CocoaLumberjack

Expand Down
1 change: 1 addition & 0 deletions OktaLogger/FileLoggers/LumberjackLoggerDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import CocoaLumberjack

class LumberjackLoggerDelegate: FileLoggerDelegate {
Expand Down
6 changes: 0 additions & 6 deletions OktaLogger/FileLoggers/OktaLoggerFileLogFormatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion OktaLogger/FileLoggers/OktaLoggerFileLogger.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -9,6 +9,7 @@
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import Foundation

@objc
Expand Down
2 changes: 2 additions & 0 deletions OktaLogger/FileLoggers/OktaLoggerFileLoggerConfig.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import FirebaseCrashlytics

/**
Expand Down Expand Up @@ -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?,
Expand All @@ -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
}
}
6 changes: 2 additions & 4 deletions OktaLogger/InstabugLogger/OktaLoggerInstabugLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion OktaLogger/OktaLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import Foundation

/**
Expand Down Expand Up @@ -136,7 +137,7 @@ open class OktaLogger: NSObject, OktaLoggerProtocol {
self.loggingDestinations = destinationDict
}

public convenience override init() {
override public convenience init() {
self.init(destinations: [])
}

Expand Down
3 changes: 2 additions & 1 deletion OktaLogger/OktaLoggerDestination.swift
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -9,6 +9,7 @@
*
* See the License for the specific language governing permissions and limitations under the License.
*/

import Foundation

/**
Expand Down
3 changes: 2 additions & 1 deletion OktaLoggerTests/Helpers/FileTestsHelper.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions OktaLoggerTests/OktaLoggerFirebaseLoggerTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit e972ff3

Please sign in to comment.