Skip to content

Commit

Permalink
Fix various code style issues
Browse files Browse the repository at this point in the history
  • Loading branch information
ffried committed Apr 16, 2024
1 parent 0e207ec commit 2566f12
Show file tree
Hide file tree
Showing 13 changed files with 39 additions and 93 deletions.
2 changes: 2 additions & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
disabled_rules:
- line_length
- function_parameter_count
- syntactic_sugar
- private_over_fileprivate

opt_in_rules:
- empty_count
Expand Down
2 changes: 1 addition & 1 deletion Dangerfile.swift
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ if danger.github?.pullRequest.title.contains("WIP") == true {
}

// Warn when there is a big PR
if let additions = danger.github?.pullRequest.additions,
if let additions = danger.github?.pullRequest.additions,
let deletions = danger.github?.pullRequest.deletions,
case let sum = additions + deletions, sum > 1000 {
warn("Pull request is relatively big (\(sum) lines changed). If this PR contains multiple changes, consider splitting it into separate PRs for easier reviews.")
Expand Down
2 changes: 1 addition & 1 deletion Demos/WebServerIPhone/Web/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ td {
}

body {
margin: 0px;
margin: 0;
}

#status {
Expand Down
12 changes: 6 additions & 6 deletions Integration/Sources/Formatter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,23 @@ import CocoaLumberjackSwift

final class Formatter: DDDispatchQueueLogFormatter {
let threadUnsafeDateFormatter: DateFormatter

override init() {
threadUnsafeDateFormatter = DateFormatter()
threadUnsafeDateFormatter.formatterBehavior = .behavior10_4
threadUnsafeDateFormatter.dateFormat = "HH:mm:ss.SSS"

super.init()
}

override func format(message logMessage: DDLogMessage) -> String {
let dateAndTime = threadUnsafeDateFormatter.string(from: logMessage.timestamp)

let logLevel: String
let logFlag = logMessage.flag
if logFlag.contains(.error) {
logLevel = "E"
} else if logFlag.contains(.warning){
} else if logFlag.contains(.warning) {
logLevel = "W"
} else if logFlag.contains(.info) {
logLevel = "I"
Expand All @@ -45,7 +45,7 @@ final class Formatter: DDDispatchQueueLogFormatter {
} else {
logLevel = "?"
}

return "\(dateAndTime) |\(logLevel)| [\(logMessage.fileName) \(logMessage.function ?? "nil")] #\(logMessage.line): \(logMessage.message)"
}
}
13 changes: 4 additions & 9 deletions Integration/Sources/ViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,27 @@ @interface ViewController ()

@implementation ViewController

- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];

if (@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)) {
[DDLog addLogger:[DDOSLogger sharedInstance]];
} else {
[DDLog addLogger:(DDTTYLogger *)[DDTTYLogger sharedInstance]];
}

DDLogVerbose(@"Verbose");
DDLogInfo(@"Info");
DDLogWarn(@"Warn");
DDLogError(@"Error");

DDLog *aDDLogInstance = [DDLog new];
if (@available(macOS 10.12, iOS 10.0, watchOS 3.0, tvOS 10.0, *)) {
[aDDLogInstance addLogger:[DDOSLogger sharedInstance]];
} else {
[aDDLogInstance addLogger:(DDTTYLogger *)[DDTTYLogger sharedInstance]];
}

DDLogVerboseToDDLog(aDDLogInstance, @"Verbose from aDDLogInstance");
DDLogInfoToDDLog(aDDLogInstance, @"Info from aDDLogInstance");
DDLogWarnToDDLog(aDDLogInstance, @"Warn from aDDLogInstance");
Expand Down
18 changes: 6 additions & 12 deletions Integration/Sources/ViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,6 @@ private func printSomething() {
}

final class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}

override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
let formatter = Formatter()
Expand All @@ -45,29 +39,29 @@ final class ViewController: UIViewController {
logger.logFormatter = formatter
DDLog.add(logger)
}

DDLogVerbose("Verbose")
DDLogDebug("Debug")
DDLogInfo("Info")
DDLogWarn("Warn")
DDLogError("Error")

printSomething()

dynamicLogLevel = ddloglevel

DDLogVerbose("Verbose")
DDLogDebug("Debug")
DDLogInfo("Info")
DDLogWarn("Warn")
DDLogError("Error")

DDLogVerbose("Verbose", level: ddloglevel)
DDLogDebug("Debug", level: ddloglevel)
DDLogInfo("Info", level: ddloglevel)
DDLogWarn("Warn", level: ddloglevel)
DDLogError("Error", level: ddloglevel)

printSomething()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,20 +16,4 @@
import WatchKit
import Foundation

final class InterfaceController: WKInterfaceController {

override func awake(withContext context: Any?) {
super.awake(withContext: context)
// Configure interface objects here.
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}
}
final class InterfaceController: WKInterfaceController {}
Original file line number Diff line number Diff line change
Expand Up @@ -17,28 +17,4 @@ import WatchKit
import Foundation
import UserNotifications

final class NotificationController: WKUserNotificationInterfaceController {

override init() {
// Initialize variables here.
super.init()

// Configure interface objects here.
}

override func willActivate() {
// This method is called when watch view controller is about to be visible to user
super.willActivate()
}

override func didDeactivate() {
// This method is called when watch view controller is no longer visible
super.didDeactivate()
}

override func didReceive(_ notification: UNNotification) {
// This method is called when a notification needs to be presented.
// Implement it if you use a dynamic notification interface.
// Populate your dynamic notification interface as quickly as possible.
}
}
final class NotificationController: WKUserNotificationInterfaceController {}
2 changes: 1 addition & 1 deletion Scripts/generate-podspec.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

set -euo pipefail
SCRIPT_NAME="$(basename $0)"
SCRIPT_NAME="$(basename "$0")"


# Functions
Expand Down
4 changes: 2 additions & 2 deletions Scripts/update-copyright.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

set -euo pipefail
SCRIPT_NAME="$(basename $0)"
SCRIPT_NAME="$(basename "$0")"

# Arg1: OLD_YEAR
# Arg2: NEW_YEAR
Expand Down Expand Up @@ -71,7 +71,7 @@ if [[ "$(uname -s)" = 'Darwin' ]]; then
EXTENDED_REGEX_FLAG_POST_PATH=''
fi

pushd "$(dirname $0)/../" > /dev/null
pushd "$(dirname "$0")/../" > /dev/null
find ${EXTENDED_REGEX_FLAG_PRE_PATH} \
. \
${EXTENDED_REGEX_FLAG_POST_PATH} \
Expand Down
17 changes: 11 additions & 6 deletions Sources/CocoaLumberjackSwift/CocoaLumberjack.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
// to endorse or promote products derived from this software without specific
// prior written permission of Deusty, LLC.

// swiftlint:disable file_length

@_exported import CocoaLumberjack
#if SWIFT_PACKAGE
import CocoaLumberjackSwiftSupport
Expand Down Expand Up @@ -227,24 +229,24 @@ public struct DDLogMessageFormat: ExpressibleByStringInterpolation {
}

@inlinable
public mutating func appendInterpolation<Convertible: ReferenceConvertible>(_ c: Convertible) {
if c is CVarArg {
public mutating func appendInterpolation<Convertible: ReferenceConvertible>(_ convertible: Convertible) {
if convertible is CVarArg {
print("""
[WARNING]: CocoaLumberjackSwift is creating a \(DDLogMessageFormat.self) with an interpolation conforming to `CVarArg` \
using the overload for `ReferenceConvertible` interpolations!
Please report this as a bug, including the following snippet:
```
Convertible: \(Convertible.self), ReferenceType: \(Convertible.ReferenceType.self), type(of: c): \(type(of: c))
Convertible: \(Convertible.self), ReferenceType: \(Convertible.ReferenceType.self), type(of: convertible): \(type(of: convertible))
```
""")
}
// This should be safe, sine the compiler should convert it to the reference.
storage.addValue(c as? CVarArg ?? c as! Convertible.ReferenceType, withSpecifier: "%@")
storage.addValue(convertible as? CVarArg ?? convertible as! Convertible.ReferenceType, withSpecifier: "%@")
}

@inlinable
public mutating func appendInterpolation<Obj: NSObject>(_ o: Obj) {
storage.addValue(o, withSpecifier: "%@")
public mutating func appendInterpolation<Obj: NSObject>(_ object: Obj) {
storage.addValue(object, withSpecifier: "%@")
}

@_disfavoredOverload
Expand Down Expand Up @@ -610,3 +612,6 @@ public func currentFileName(_ fileName: StaticString = #file) -> String {
public func CurrentFileName(_ fileName: StaticString = #file) -> String {
currentFileName(fileName)
}
// swiftlint:enable identifier_name

// swiftlint:enable file_length
8 changes: 3 additions & 5 deletions Tests/CocoaLumberjackSwiftTests/DDLogCombineTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ final class DDLogCombineTests: XCTestCase {
private var subscriptions = Set<AnyCancellable>()

private var logFormatter: DDLogFileFormatterDefault {
//let's return a formatter that doesn't change based where the
//test is being run.
// let's return a formatter that doesn't change based where the test is being run.
let formatter = DateFormatter()
formatter.dateFormat = "yyyy/MM/dd HH:mm:ss:SSS"
formatter.calendar = Calendar(identifier: .gregorian)
Expand Down Expand Up @@ -164,7 +163,7 @@ final class DDLogCombineTests: XCTestCase {
XCTAssertEqual(receivedValue, ["2001/01/01 00:01:40:000 An error occurred",
"2001/01/01 00:03:20:000 WARNING: this is incorrect"])
}

func testQOSNameInstantiation() {
let name = "UI"
let qos: qos_class_t = {
Expand All @@ -175,10 +174,9 @@ final class DDLogCombineTests: XCTestCase {
return QOS_CLASS_UNSPECIFIED
}
}()

XCTAssertEqual(qos, QOS_CLASS_USER_INTERACTIVE)
}
}

#endif
#endif
8 changes: 0 additions & 8 deletions Tests/CocoaLumberjackSwiftTests/DDLogMessageFormatTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ import XCTest
@testable import CocoaLumberjackSwift

final class DDLogMessageFormatTests: XCTestCase {
override func setUp() {
super.setUp()
}

override func tearDown() {
super.tearDown()
}

func testMessageFormatCreationWithNoArgs() {
let format: DDLogMessageFormat = "Message with no args"
let expectedFormat: String = "Message with no args"
Expand Down

0 comments on commit 2566f12

Please sign in to comment.