Skip to content

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
Shane Osbourne committed May 6, 2023
1 parent 5c32232 commit f7291ba
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Sources/UserScript/UserScriptMessageEncryption.swift
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ extension UserScriptMessageEncryption {
return params
}

public func encrypt(reply: String, with params: SecureMessagingParams, into webView: WKWebView?) {
public func encrypt(reply: String, with params: SecureMessagingParams, into webView: WKWebView?) {

guard let encryption = try? encrypter.encryptReply(reply, key: params.key, iv: params.iv) else { return }

Expand Down
13 changes: 6 additions & 7 deletions Sources/UserScript/UserScriptMessaging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,12 @@ public protocol Subfeature {

/// Subfeatures may sometime need access to the message broker - for example to push messages into the page
var broker: UserScriptMessageBroker? { get set }
func with(broker: UserScriptMessageBroker) -> Void;
func with(broker: UserScriptMessageBroker)
}

extension Subfeature {
/// providing a blank implementation since not all features will need this
public func with(broker: UserScriptMessageBroker) -> Void {
public func with(broker: UserScriptMessageBroker) {
// nothing
}
}
Expand All @@ -76,7 +76,7 @@ public protocol UserScriptMessaging: UserScript {

extension UserScriptMessaging {
public func registerSubFeature(delegate: Subfeature) {
delegate.with(broker: broker);
delegate.with(broker: broker)
broker.registerSubFeature(delegate: delegate)
}
}
Expand Down Expand Up @@ -123,7 +123,7 @@ public final class UserScriptMessageBroker: NSObject, UserScriptMessageEncryptio
if #available(macOS 11.0, iOS 14.0, *) {
config.hasModernWebkitAPI = true
}
return config;
return config
}

public func push(method: String, params: Encodable?, for delegate: Subfeature, into webView: WKWebView) {
Expand All @@ -134,7 +134,7 @@ public final class UserScriptMessageBroker: NSObject, UserScriptMessageEncryptio
params: params ?? [:] as [String: String]
)
else {
return;
return
}
if #available(macOS 11.0, iOS 14.0, *) {
if !self.requiresRunInPageContentWorld {
Expand Down Expand Up @@ -180,7 +180,6 @@ public final class UserScriptMessageBroker: NSObject, UserScriptMessageEncryptio
return .error(.invalidParams)
}


/// Now try to match the message to a registered delegate
guard let delegate = callbacks[featureName] else {
return .error(.notFoundFeature(featureName))
Expand Down Expand Up @@ -235,7 +234,7 @@ public final class UserScriptMessageBroker: NSObject, UserScriptMessageEncryptio
/// As far as the client is concerned, a `notification` is fire-and-forget
case .notify(let handler, let notification):
do {
try await handler(notification.params, original);
try await handler(notification.params, original)
} catch {
os_log("UserScriptMessaging: unhandled exception %s", type: .error, String(describing: error.localizedDescription))
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/UserScript/UserScriptMessagingSchema.swift
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@ public struct SubscriptionEvent {
}

public struct WebkitMessagingConfig: Encodable {
let webkitMessageHandlerNames: [String];
let secret: String;
let webkitMessageHandlerNames: [String]
let secret: String
var hasModernWebkitAPI: Bool
}

Expand Down
8 changes: 4 additions & 4 deletions Tests/UserScriptTests/UserScriptMessagingTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class UserScriptMessagingTests: XCTestCase {
])

do {
let _ = try await testee.execute(action: action, original: original);
_ = try await testee.execute(action: action, original: original)
} catch let error {
XCTAssertEqual(error.localizedDescription, "feature named `this_feature_doesnt_exist` was not found")
}
Expand All @@ -162,7 +162,7 @@ class UserScriptMessagingTests: XCTestCase {
])

do {
let _ = try await testee.execute(action: action, original: original)
_ = try await testee.execute(action: action, original: original)
} catch let error {
XCTAssertEqual(error.localizedDescription, "the incoming message is ignored because the feature `fooBarFeature` couldn't provide a handler for method `an_unknown_method_name_but_no_id`")
}
Expand All @@ -181,7 +181,7 @@ class UserScriptMessagingTests: XCTestCase {
])

do {
let _ = try await testee.execute(action: action, original: original)
_ = try await testee.execute(action: action, original: original)
} catch {
XCTAssertEqual(error.localizedDescription, "The incoming message was not valid - one or more of 'featureName', 'method' or 'context' was missing")
}
Expand Down Expand Up @@ -240,7 +240,7 @@ struct TestDelegate: Subfeature {

/// An example that represents handling a [NotificationMessage](https://duckduckgo.github.io/content-scope-scripts/classes/Messaging_Schema.NotificationMessage.html)
func notifyExample(params: Any, original: WKScriptMessage) async throws -> Encodable? {
print("not replying...");
print("not replying...")
return nil
}

Expand Down

0 comments on commit f7291ba

Please sign in to comment.