Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SwiftLint fixes part 3 #462

Merged
merged 35 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
951f5ce
Autofix many SwiftLint warnings.
samsymons Aug 8, 2023
acdcceb
Format parts of EmailManager.
samsymons Aug 8, 2023
cdd1326
Disable line length warnings in SecureVaultManager tests for now.
samsymons Aug 8, 2023
cef2877
Allow force try calls within BookmarksProviderTests.
samsymons Aug 8, 2023
fe5fcba
Disable force_cast and force_try errors in test files.
samsymons Aug 8, 2023
fdadbde
Disable some line_length warnings.
samsymons Aug 8, 2023
31e9e9b
Allow file_length in test files also.
samsymons Aug 8, 2023
0ce5d41
Fix some duplicate imports.
samsymons Aug 8, 2023
fc6ff4f
Fix a handful of line length warnings.
samsymons Aug 8, 2023
e8ce385
Fix blanket disable command warnings.
samsymons Aug 8, 2023
48f770a
Disable line_length in test files.
samsymons Aug 8, 2023
e8a23a1
Fix a few more test suite issues.
samsymons Aug 8, 2023
7f15591
Continue to fix test suite lint warnings.
samsymons Aug 8, 2023
0766812
Disable some more lint types in test files. Type body length shouldn’…
samsymons Aug 8, 2023
8996e24
Begin working on all remaining lint warnings.
samsymons Aug 8, 2023
f530be1
Fix some force_try usage.
samsymons Aug 8, 2023
521151a
More SwiftLint fixes.
samsymons Aug 8, 2023
161a598
Make an actual functional change to resolve a warning.
samsymons Aug 8, 2023
0c922ae
Fix some indentation.
samsymons Aug 8, 2023
1945cf3
Add a couple blanket statements where the violations aren’t worse to …
samsymons Aug 8, 2023
83f2726
Fixing more failures.
samsymons Aug 8, 2023
5ff9eaf
More fixes again. I can’t keep coming up with original commit message…
samsymons Aug 8, 2023
c100535
Working through more lint failures.
samsymons Aug 8, 2023
1f90c08
In the home stretch now.
samsymons Aug 8, 2023
e429f0f
Fairly large batch of changes here.
samsymons Aug 8, 2023
17a813b
More warnings fixed.
samsymons Aug 8, 2023
8a281f2
Final lint changes.
samsymons Aug 8, 2023
4dab2fc
Merge branch 'main' into sam/swiftlint-fixes-part-3
samsymons Aug 16, 2023
8f95abc
Resolve new lint warnings.
samsymons Aug 16, 2023
ada2b84
Undo a change that isn’t needed, and add the scripts directory to the…
samsymons Aug 16, 2023
1218e11
Remove an unnecessary disable/enable block.
samsymons Aug 16, 2023
93f9de9
Fix some newlines in SecureStorageError.
samsymons Aug 16, 2023
3bd6db2
Xcode really doesn’t want to trim whitespace huh?
samsymons Aug 16, 2023
59510b6
Small tuples only, please
samsymons Aug 17, 2023
aebf349
Small tuples only: unit tests edition
samsymons Aug 17, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ type_name:

excluded:
- .build
- scripts/
6 changes: 5 additions & 1 deletion Sources/Bookmarks/BookmarkListViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,11 @@ public class BookmarkListViewModel: BookmarkListInteracting, ObservableObject {

public var totalBookmarksCount: Int {
let countRequest = BookmarkEntity.fetchRequest()
countRequest.predicate = NSPredicate(format: "%K == false && %K == NO", #keyPath(BookmarkEntity.isFolder), #keyPath(BookmarkEntity.isPendingDeletion))
countRequest.predicate = NSPredicate(
format: "%K == false && %K == NO",
#keyPath(BookmarkEntity.isFolder),
#keyPath(BookmarkEntity.isPendingDeletion)
)

return (try? context.count(for: countRequest)) ?? 0
}
Expand Down
5 changes: 4 additions & 1 deletion Sources/Bookmarks/BookmarkUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ public struct BookmarkUtils {
predicate: NSPredicate = NSPredicate(value: true),
context: NSManagedObjectContext) -> BookmarkEntity? {
let request = BookmarkEntity.fetchRequest()
let urlPredicate = NSPredicate(format: "%K == %@ AND %K == NO", #keyPath(BookmarkEntity.url), url.absoluteString, #keyPath(BookmarkEntity.isPendingDeletion))
let urlPredicate = NSPredicate(format: "%K == %@ AND %K == NO",
#keyPath(BookmarkEntity.url),
url.absoluteString,
#keyPath(BookmarkEntity.isPendingDeletion))
request.predicate = NSCompoundPredicate(andPredicateWithSubpredicates: [urlPredicate, predicate])
request.returnsObjectsAsFaults = false
request.fetchLimit = 1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,11 @@ public class BookmarkCoreDataImporter {

private func bookmarkURLToID(in context: NSManagedObjectContext) throws -> [String: NSManagedObjectID] {
let fetch = NSFetchRequest<NSFetchRequestResult>(entityName: "BookmarkEntity")
fetch.predicate = NSPredicate(format: "%K == false && %K == NO", #keyPath(BookmarkEntity.isFolder), #keyPath(BookmarkEntity.isPendingDeletion))
fetch.predicate = NSPredicate(
format: "%K == false && %K == NO",
#keyPath(BookmarkEntity.isFolder),
#keyPath(BookmarkEntity.isPendingDeletion)
)
fetch.resultType = .dictionaryResultType

let idDescription = NSExpressionDescription()
Expand Down
6 changes: 5 additions & 1 deletion Sources/Bookmarks/MenuBookmarksViewModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,11 @@ public class MenuBookmarksViewModel: MenuBookmarksInteracting {

public func favorite(for url: URL) -> BookmarkEntity? {
BookmarkUtils.fetchBookmark(for: url,
predicate: NSPredicate(format: "%K != nil AND %K == NO", #keyPath(BookmarkEntity.favoriteFolder), #keyPath(BookmarkEntity.isPendingDeletion)),
predicate: NSPredicate(
format: "%K != nil AND %K == NO",
#keyPath(BookmarkEntity.favoriteFolder),
#keyPath(BookmarkEntity.isPendingDeletion)
),
context: context)
}

Expand Down
6 changes: 4 additions & 2 deletions Sources/BookmarksTestsUtils/BookmarkTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import CoreData
import Foundation
import XCTest

// swiftlint:disable line_length
// swiftlint:disable cyclomatic_complexity function_body_length line_length
public struct ModifiedAtConstraint {
var check: (Date?) -> Void

Expand Down Expand Up @@ -198,6 +198,7 @@ public struct BookmarkTree {
return (rootFolder, orphans)
}

// swiftlint:disable large_tuple
@discardableResult
public func createEntitiesForCheckingModifiedAt(in context: NSManagedObjectContext) -> (BookmarkEntity, [BookmarkEntity], [String: ModifiedAtConstraint]) {
let rootFolder = BookmarkUtils.fetchRootFolder(context)!
Expand All @@ -220,6 +221,7 @@ public struct BookmarkTree {
}
return (rootFolder, orphans, modifiedAtConstraints)
}
// swiftlint:enable large_tuple

let modifiedAt: Date?
let modifiedAtConstraint: ModifiedAtConstraint?
Expand Down Expand Up @@ -356,4 +358,4 @@ public extension XCTestCase {
}
}
}
// swiftlint:enable line_length
// swiftlint:enable cyclomatic_complexity function_body_length line_length
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ extension AutofillUserScript {
self.emailDelegate?.autofillUserScriptDidRequestUserData(self) { username, _, _, _ in
if let username = username {
let autogenerated = alias != username && autosave // Only consider private emails as autogenerated
let credentials = AutofillUserScript.IncomingCredentials(username: "\(alias)@\(EmailManager.emailDomain)", password: nil, autogenerated: autogenerated)
let credentials = AutofillUserScript.IncomingCredentials(username: "\(alias)@\(EmailManager.emailDomain)",
password: nil,
autogenerated: autogenerated)
let data = DetectedAutofillData(identity: nil, credentials: credentials, creditCard: nil, trigger: .emailProtection)
self.vaultDelegate?.autofillUserScript(self, didRequestStoreDataForDomain: domain, data: data)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import WebKit
import Common
import UserScript

// swiftlint:disable file_length
// swiftlint:disable line_length file_length

public enum RequestVaultCredentialsAction: String, Codable {
case none
Expand Down Expand Up @@ -913,4 +913,4 @@ extension AutofillUserScript.AskToUnlockProviderResponse {

}

// swiftlint:enable file_length
// swiftlint:enable line_length file_length
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ public protocol OverlayAutofillUserScriptDelegate: AnyObject {
/// Represents the last tab host, is used to verify messages origin from and selecting of credentials
var overlayAutofillUserScriptLastOpenHost: String? { get }
/// Handles filling the credentials back from the top autofill into the child
func overlayAutofillUserScript(_ overlayAutofillUserScript: OverlayAutofillUserScript, messageSelectedCredential: [String: String], _ configType: String)
func overlayAutofillUserScript(_ overlayAutofillUserScript: OverlayAutofillUserScript,
messageSelectedCredential: [String: String],
_ configType: String)
/// Closes the overlay
func overlayAutofillUserScriptClose(_ overlayAutofillUserScript: OverlayAutofillUserScript)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,10 @@ public protocol ContentOverlayUserScriptDelegate: AnyObject {
/// Closes the overlay
func websiteAutofillUserScriptCloseOverlay(_ websiteAutofillUserScript: WebsiteAutofillUserScript?)
/// Opens the overlay
func websiteAutofillUserScript(_ websiteAutofillUserScript: WebsiteAutofillUserScript, willDisplayOverlayAtClick: CGPoint?, serializedInputContext: String, inputPosition: CGRect)
func websiteAutofillUserScript(_ websiteAutofillUserScript: WebsiteAutofillUserScript,
willDisplayOverlayAtClick: CGPoint?,
serializedInputContext: String,
inputPosition: CGRect)
}

public class WebsiteAutofillUserScript: AutofillUserScript {
Expand Down Expand Up @@ -131,7 +134,9 @@ public class WebsiteAutofillUserScript: AutofillUserScript {

} else if let selectedDetailsData = selectedDetailsData {
self.selectedDetailsData = nil
response = GetSelectedCredentialsResponse(type: CredentialsResponse.ok, data: selectedDetailsData.data, configType: selectedDetailsData.configType)
response = GetSelectedCredentialsResponse(type: CredentialsResponse.ok,
data: selectedDetailsData.data,
configType: selectedDetailsData.configType)
}

if let json = try? JSONEncoder().encode(response),
Expand All @@ -150,7 +155,9 @@ extension WebsiteAutofillUserScript: OverlayAutofillUserScriptDelegate {
close()
}

public func overlayAutofillUserScript(_ overlayAutofillUserScript: OverlayAutofillUserScript, messageSelectedCredential: [String: String], _ configType: String) {
public func overlayAutofillUserScript(_ overlayAutofillUserScript: OverlayAutofillUserScript,
messageSelectedCredential: [String: String],
_ configType: String) {
guard let currentOverlayTab = currentOverlayTab else { return }
currentOverlayTab.websiteAutofillUserScriptCloseOverlay(self)
selectedDetailsData = SelectedDetailsData(data: messageSelectedCredential, configType: configType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ public enum AdClickAttributionEvents {
case adAttributionPageLoads
}

// swiftlint:disable identifier_name

public enum AdClickAttributionDebugEvents {

case adAttributionGlobalAttributedRulesDoNotExist
Expand All @@ -49,5 +47,3 @@ public enum AdClickAttributionDebugEvents {
case adAttributionDetectionHeuristicsDidNotMatchDomain

}

// swiftlint:enable identifier_name
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public protocol AdClickAttributionLogicDelegate: AnyObject {
forVendor vendor: String?)
}

// swiftlint:disable:next type_body_length
public class AdClickAttributionLogic {

public enum State {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ import TrackerRadarKit
import Combine
import Common

// swiftlint:disable file_length
// swiftlint:disable type_body_length
// swiftlint:disable file_length type_body_length

public protocol CompiledRuleListsSource {

Expand Down Expand Up @@ -337,11 +336,9 @@ public class ContentBlockerRulesManager: CompiledRuleListsSource {
var cnames = [TrackerData.CnameDomain: TrackerData.TrackerDomain]()
if let tdsCnames = tds.cnames {
for pair in tdsCnames {
for domain in domains.keys {
if pair.value.hasSuffix(domain) {
cnames[pair.key] = pair.value
break
}
for domain in domains.keys where pair.value.hasSuffix(domain) {
cnames[pair.key] = pair.value
break
}
}
}
Expand Down Expand Up @@ -450,3 +447,5 @@ public class ContentBlockerRulesManager: CompiledRuleListsSource {
}

}

// swiftlint:enable file_length type_body_length
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ open class ContentBlockerRulesUserScript: NSObject, UserScript {
return temporaryUnprotectedDomains
}

// swiftlint:disable:next cyclomatic_complexity function_body_length
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
guard let delegate = delegate else { return }
guard delegate.contentBlockerRulesUserScriptShouldProcessTrackers(self) else { return }
Expand Down
7 changes: 4 additions & 3 deletions Sources/BrowserServicesKit/Email/EmailManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ public enum EmailManagerPermittedAddressType {
case none
}

// swiftlint:disable identifier_name
public protocol EmailManagerAliasPermissionDelegate: AnyObject {

func emailManager(_ emailManager: EmailManager,
didRequestPermissionToProvideAliasWithCompletion: @escaping (EmailManagerPermittedAddressType, _ autosave: Bool) -> Void)

}
// swiftlint:enable identifier_name

public enum EmailManagerRequestDelegateError: Error {
case serverError(statusCode: Int)
Expand Down Expand Up @@ -648,7 +646,10 @@ private extension EmailManager {
requested: url,
method: Constants.RequestMethods.put,
headers: emailHeaders,
parameters: [Constants.RequestParameters.address: alias, Constants.RequestParameters.status: "\(active)"],
parameters: [
Constants.RequestParameters.address: alias,
Constants.RequestParameters.status: "\(active)"
],
httpBody: nil,
timeoutInterval: timeoutInterval)
let response: EmailAliasStatusResponse = try JSONDecoder().decode(EmailAliasStatusResponse.self, from: data)
Expand Down
38 changes: 20 additions & 18 deletions Sources/BrowserServicesKit/FeatureFlagger/FeatureFlagger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,26 @@ public class DefaultFeatureFlagger: FeatureFlagger {
/// where the final value should come from.
///
/// Example:
//
// public enum FeatureFlag: FeatureFlagSourceProviding {
// case sync
// case autofill
// case cookieConsent
// case duckPlayer
//
// var source: FeatureFlagSource {
// case .sync:
// return .disabled
// case .cookieConsent:
// return .internalOnly
// case .credentialsAutofill:
// return .remoteDevelopment(.subfeature(AutofillSubfeature.credentialsAutofill))
// case .duckPlayer:
// return .remoteReleasable(.feature(.duckPlayer))
// }
// }
///
/// ```
/// public enum FeatureFlag: FeatureFlagSourceProviding {
/// case sync
/// case autofill
/// case cookieConsent
/// case duckPlayer
///
/// var source: FeatureFlagSource {
/// case .sync:
/// return .disabled
/// case .cookieConsent:
/// return .internalOnly
/// case .credentialsAutofill:
/// return .remoteDevelopment(.subfeature(AutofillSubfeature.credentialsAutofill))
/// case .duckPlayer:
/// return .remoteReleasable(.feature(.duckPlayer))
/// }
/// }
/// ```
public protocol FeatureFlagSourceProviding {
var source: FeatureFlagSource { get }
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/BrowserServicesKit/GPC/GPCRequestFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public struct GPCRequestFactory {
}

public func requestForGPC(basedOn incomingRequest: URLRequest,
config: PrivacyConfiguration,
gpcEnabled: Bool) -> URLRequest? {
config: PrivacyConfiguration,
gpcEnabled: Bool) -> URLRequest? {

func removingHeader(fromRequest incomingRequest: URLRequest) -> URLRequest? {
var request = incomingRequest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,14 +118,10 @@ public class AMPCanonicalExtractor: NSObject {
let urlStr = url.absoluteString

let ampKeywords = TrackingLinkSettings(fromConfig: privacyConfig).ampKeywords

for keyword in ampKeywords {
if urlStr.contains(keyword) {
return true
}

return ampKeywords.contains { keyword in
return urlStr.contains(keyword)
}

return false
}

private func buildUserScript() -> WKUserScript {
Expand Down
6 changes: 2 additions & 4 deletions Sources/BrowserServicesKit/LinkProtection/LinkCleaner.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,8 @@ public class LinkCleaner {

public func ampFormat(matching url: URL) -> String? {
let ampFormats = TrackingLinkSettings(fromConfig: privacyConfig).ampLinkFormats
for format in ampFormats {
if url.absoluteString.matches(pattern: format) {
return format
}
for format in ampFormats where url.absoluteString.matches(pattern: format) {
samsymons marked this conversation as resolved.
Show resolved Hide resolved
return format
}

return nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,12 @@ public struct LinkProtection {
onFinishExtracting: @escaping () -> Void,
onLinkRewrite: @escaping (URL, WKNavigationAction) -> Void,
policyDecisionHandler: @escaping (WKNavigationActionPolicy) -> Void) -> Bool {
requestTrackingLinkRewrite(initiatingURL: initiatingURL, destinationURL: navigationAction.request.url!, onStartExtracting: onStartExtracting, onFinishExtracting: onFinishExtracting, onLinkRewrite: { onLinkRewrite($0, navigationAction) }, policyDecisionHandler: { policyDecisionHandler($0 ? .allow : .cancel) })
requestTrackingLinkRewrite(initiatingURL: initiatingURL,
destinationURL: navigationAction.request.url!,
onStartExtracting: onStartExtracting,
onFinishExtracting: onFinishExtracting,
onLinkRewrite: { onLinkRewrite($0, navigationAction) },
policyDecisionHandler: { policyDecisionHandler($0 ? .allow : .cancel) })
}
// swiftlint:enable function_parameter_count

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,8 @@ public struct AppPrivacyConfiguration: PrivacyConfiguration {
}

private func isRolloutEnabled(subfeature: any PrivacySubfeature,
rollouts: [PrivacyConfigurationData.PrivacyFeature.Feature.Rollout],
randomizer: (Range<Double>) -> Double) -> Bool {
rollouts: [PrivacyConfigurationData.PrivacyFeature.Feature.Rollout],
randomizer: (Range<Double>) -> Double) -> Bool {
// Empty rollouts should be default enabled
guard !rollouts.isEmpty else { return true }

Expand Down Expand Up @@ -139,7 +139,9 @@ public struct AppPrivacyConfiguration: PrivacyConfiguration {
return true
}

public func isSubfeatureEnabled(_ subfeature: any PrivacySubfeature, versionProvider: AppVersionProvider, randomizer: (Range<Double>) -> Double) -> Bool {
public func isSubfeatureEnabled(_ subfeature: any PrivacySubfeature,
versionProvider: AppVersionProvider,
randomizer: (Range<Double>) -> Double) -> Bool {
guard isEnabled(featureKey: subfeature.parent, versionProvider: versionProvider) else {
return false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,12 @@ public struct PrivacyConfigurationData {
self.hash = json[CodingKeys.hash.rawValue] as? String
}

public init(state: FeatureState, exceptions: [ExceptionEntry], settings: [String: Any] = [:], features: Features = [:], minSupportedVersion: String? = nil, hash: String? = nil) {
public init(state: FeatureState,
exceptions: [ExceptionEntry],
settings: [String: Any] = [:],
features: Features = [:],
minSupportedVersion: String? = nil,
hash: String? = nil) {
self.state = state
self.exceptions = exceptions
self.settings = settings
Expand Down
Loading