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 refactoring #882

Merged
merged 3 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 6 additions & 7 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,13 @@ disabled_rules:
- line_length
- type_name
- implicit_getter
- function_parameter_count
- trailing_comma
- nesting
- opening_brace
- function_parameter_count
- function_body_length
- file_length
- type_body_length

opt_in_rules:
- file_header
Expand Down Expand Up @@ -40,15 +43,11 @@ analyzer_rules: # Rules run by `swiftlint analyze`
- explicit_self

# Rule Config
cyclomatic_complexity:
ignores_case_statements: true
identifier_name:
min_length: 1
max_length: 1000
file_length:
warning: 1200
error: 1200
type_body_length:
warning: 500
error: 500
large_tuple:
warning: 4
error: 5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down Expand Up @@ -385,6 +385,34 @@
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "BrowserServicesKitTestsUtils"
BuildableName = "BrowserServicesKitTestsUtils"
BlueprintName = "BrowserServicesKitTestsUtils"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "RemoteMessagingTestsUtils"
BuildableName = "RemoteMessagingTestsUtils"
BlueprintName = "RemoteMessagingTestsUtils"
ReferencedContainer = "container:">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1540"
version = "1.8">
version = "1.7">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES"
Expand Down
3 changes: 0 additions & 3 deletions Plugins/SwiftLintPlugin/SwiftLintPlugin.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ struct SwiftLintPlugin: BuildToolPlugin {
)
}

// swiftlint:disable function_body_length
private func createBuildCommands(
target: String,
inputFiles: [Path],
Expand Down Expand Up @@ -184,8 +183,6 @@ struct SwiftLintPlugin: BuildToolPlugin {

return result
}
// swiftlint:enable function_body_length

}

#if canImport(XcodeProjectPlugin)
Expand Down
3 changes: 0 additions & 3 deletions Sources/BookmarksTestDBBuilder/BookmarksTestDBBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import Persistence
import Bookmarks

// swiftlint:disable force_try
// swiftlint:disable function_body_length

@main
struct BookmarksTestDBBuilder {
Expand Down Expand Up @@ -255,7 +254,6 @@ public extension BookmarkEntity {
makeWithModifiedAtConstraints(with: treeNode, rootFolder: rootFolder, favoritesFolders: favoritesFolders, in: context)
}

// swiftlint:disable:next cyclomatic_complexity
@discardableResult static func makeWithModifiedAtConstraints(with treeNode: BookmarkTreeNode, rootFolder: BookmarkEntity, favoritesFolders: [BookmarkEntity], in context: NSManagedObjectContext) -> BookmarkEntity {
var entity: BookmarkEntity!

Expand Down Expand Up @@ -319,4 +317,3 @@ public extension BookmarkEntity {
}

// swiftlint:enable force_try
// swiftlint:enable function_body_length
13 changes: 9 additions & 4 deletions Sources/BookmarksTestsUtils/BookmarkTree.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import CoreData
import Foundation
import XCTest

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

Expand Down Expand Up @@ -261,12 +260,19 @@ public struct BookmarkTree {

public extension BookmarkEntity {
@discardableResult
static func make(with treeNode: BookmarkTreeNode, rootFolder: BookmarkEntity, favoritesFolders: [BookmarkEntity], in context: NSManagedObjectContext) -> BookmarkEntity {
static func make(with treeNode: BookmarkTreeNode,
rootFolder: BookmarkEntity,
favoritesFolders: [BookmarkEntity],
in context: NSManagedObjectContext) -> BookmarkEntity {
makeWithModifiedAtConstraints(with: treeNode, rootFolder: rootFolder, favoritesFolders: favoritesFolders, in: context).0
}

@discardableResult
static func makeWithModifiedAtConstraints(with treeNode: BookmarkTreeNode, rootFolder: BookmarkEntity, favoritesFolders: [BookmarkEntity], in context: NSManagedObjectContext) -> (BookmarkEntity, [String: ModifiedAtConstraint]) {
// swiftlint:disable:next cyclomatic_complexity
static func makeWithModifiedAtConstraints(with treeNode: BookmarkTreeNode,
rootFolder: BookmarkEntity,
favoritesFolders: [BookmarkEntity],
in context: NSManagedObjectContext) -> (BookmarkEntity, [String: ModifiedAtConstraint]) {
var entity: BookmarkEntity!

var queues: [[BookmarkTreeNode]] = [[treeNode]]
Expand Down Expand Up @@ -405,4 +411,3 @@ public extension XCTestCase {
}
}
}
// swiftlint:enable cyclomatic_complexity function_body_length
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ public class AutofillUserScript: NSObject, UserScript, UserScriptMessageEncrypti
return jsonString
}()

// swiftlint:disable:next cyclomatic_complexity
public func messageHandlerFor(_ messageName: String) -> MessageHandler? {
guard let message = MessageName(rawValue: messageName) else {
os_log("Failed to parse Autofill User Script message: '%{public}s'", log: .userScripts, type: .debug, messageName)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ open class ContentBlockerRulesUserScript: NSObject, UserScript {
return temporaryUnprotectedDomains
}

// swiftlint:disable:next cyclomatic_complexity function_body_length
// swiftlint:disable:next cyclomatic_complexity
public func userContentController(_ userContentController: WKUserContentController, didReceive message: WKScriptMessage) {
guard let delegate = delegate else { return }
guard delegate.contentBlockerRulesUserScriptShouldProcessTrackers(self) else { return }
Expand Down
2 changes: 0 additions & 2 deletions Sources/BrowserServicesKit/Email/EmailManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ public enum EmailManagerRequestDelegateError: Error {
case decodingError
}

// swiftlint:disable function_parameter_count
public protocol EmailManagerRequestDelegate: AnyObject {

var activeTask: URLSessionTask? { get set }
Expand All @@ -106,7 +105,6 @@ public protocol EmailManagerRequestDelegate: AnyObject {
error: EmailKeychainAccessError)

}
// swiftlint:enable function_parameter_count

public extension Notification.Name {
static let emailDidSignIn = Notification.Name("com.duckduckgo.browserServicesKit.EmailDidSignIn")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public struct LinkProtection {
}
}

// swiftlint:disable function_parameter_count
public func requestTrackingLinkRewrite(initiatingURL: URL?,
destinationRequest: URLRequest,
onStartExtracting: () -> Void,
Expand Down Expand Up @@ -147,7 +146,6 @@ public struct LinkProtection {
onLinkRewrite: { onLinkRewrite($0, navigationAction) },
policyDecisionHandler: { policyDecisionHandler($0 ? .allow : .cancel) })
}
// swiftlint:enable function_parameter_count

@MainActor
public func requestTrackingLinkRewrite(initiatingURL: URL?,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import Foundation
import GRDB
import SecureStorage

// swiftlint:disable file_length

public protocol AutofillDatabaseProvider: SecureStorageDatabaseProvider {

func accounts() throws -> [SecureVaultModels.WebsiteAccount]
Expand Down Expand Up @@ -825,7 +823,6 @@ extension DefaultAutofillDatabaseProvider {

}

// swiftlint:disable:next function_body_length
static func migrateV6(database: Database) throws {

try database.alter(table: SecureVaultModels.Identity.databaseTableName) {
Expand Down Expand Up @@ -1366,5 +1363,3 @@ extension SecureVaultModels.Identity: PersistableRecord, FetchableRecord {
public static var databaseTableName: String = "identities"

}

// swiftlint:enable file_length
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ extension SecureVaultManager: AutofillSecureVaultDelegate {
delegate?.secureVaultManager(self, didRequestPasswordManagerForDomain: domain)
}

// swiftlint:disable:next cyclomatic_complexity function_body_length
// swiftlint:disable:next cyclomatic_complexity
public func autofillUserScript(_: AutofillUserScript,
didRequestStoreDataForDomain domain: String,
data: AutofillUserScript.DetectedAutofillData) {
Expand Down Expand Up @@ -338,7 +338,6 @@ extension SecureVaultManager: AutofillSecureVaultDelegate {

}

// swiftlint:disable function_body_length
public func autofillUserScript(_: AutofillUserScript,
didRequestCredentialsForDomain domain: String,
subType: AutofillUserScript.GetAutofillDataSubType,
Expand Down Expand Up @@ -404,7 +403,6 @@ extension SecureVaultManager: AutofillSecureVaultDelegate {
completionHandler(nil, credentialsProvider, .none)
}
}
// swiftlint:enable function_body_length

public func autofillUserScript(_: AutofillUserScript,
didRequestCredentialsForAccount accountId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,12 @@ public class MockEmailManagerRequestDelegate: EmailManagerRequestDelegate {
public var waitlistTimestamp: Int = 1
public var didSendMockAliasRequest: () -> Void

// swiftlint:disable function_parameter_count
public func emailManager(_ emailManager: EmailManager, requested url: URL, method: String, headers: [String: String], parameters: [String: String]?, httpBody: Data?, timeoutInterval: TimeInterval) async throws -> Data {
switch url.absoluteString {
case EmailUrls.Url.emailAlias: return try processMockAliasRequest().get()
default: fatalError("\(#file): Unsupported URL passed to mock request delegate: \(url)")
}
}
// swiftlint:enable function_parameter_count

public var keychainAccessErrorAccessType: EmailKeychainAccessType?
public var keychainAccessError: EmailKeychainAccessError?
Expand Down
4 changes: 0 additions & 4 deletions Sources/Common/Logging.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ extension ProcessInfo {
}
}

// swiftlint:disable function_parameter_count

// MARK: - message first

@inlinable
Expand Down Expand Up @@ -326,5 +324,3 @@ public func os_log(_ type: OSLogType, _ message: @autoclosure () -> String, _ vi
public func os_log(_ message: @autoclosure () -> String, _ visibility: LogVisibility = .private) {
os_log(.default, log: .default, message(), visibility)
}

// swiftlint:enable function_parameter_count
1 change: 0 additions & 1 deletion Sources/DDGSync/DDGSync.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ public class DDGSync: DDGSyncing {
}
}

// swiftlint:disable:next function_body_length
private func updateAccount(_ account: SyncAccount? = nil) throws {
guard account?.state != .initializing else {
assertionFailure("Sync has not been initialized properly")
Expand Down
1 change: 0 additions & 1 deletion Sources/DDGSync/internal/RemoteAPIRequestCreator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ struct RemoteAPIRequestCreator: RemoteAPIRequestCreating {
self.getLog = log
}

// swiftlint:disable:next function_parameter_count
public func createRequest(
url: URL,
method: HTTPRequestMethod,
Expand Down
1 change: 0 additions & 1 deletion Sources/DDGSync/internal/SyncDependencies.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,6 @@ protocol HTTPRequesting {
}

protocol RemoteAPIRequestCreating {
// swiftlint:disable:next function_parameter_count
func createRequest(url: URL,
method: HTTPRequestMethod,
headers: [String: String],
Expand Down
1 change: 0 additions & 1 deletion Sources/DDGSync/internal/SyncOperation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,6 @@ final class SyncOperation: Operation, @unchecked Sendable {
try await sync(fetchOnly: fetchOnly, dataProviders: dataProviders)
}

// swiftlint:disable:next cyclomatic_complexity function_body_length
func sync(fetchOnly: Bool, dataProviders: [DataProviding] = []) async throws {
os_log(.debug, log: log, "Sync Operation Started. Fetch-only: %{public}s", String(fetchOnly))
defer {
Expand Down
1 change: 0 additions & 1 deletion Sources/History/HistoryStore.swift
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,6 @@ final public class HistoryStore: HistoryStoring {
}
}

// swiftlint:disable:next function_body_length
public func save(entry: HistoryEntry) -> Future<[(id: Visit.ID, date: Date)], Error> {
return Future { [weak self] promise in
self?.context.perform { [weak self] in
Expand Down
12 changes: 2 additions & 10 deletions Sources/Navigation/DistributedNavigationDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ private extension DistributedNavigationDelegate {
static var sigIntRaisedForResponders = Set<String>()
#endif

// swiftlint:disable function_parameter_count
/// continues until first non-nil Navigation Responder decision and returned to the `completion` callback
func makeAsyncDecision<T>(for actionDebugInfo: some CustomDebugStringConvertible,
boundToLifetimeOf webView: WKWebView,
Expand Down Expand Up @@ -170,7 +169,6 @@ private extension DistributedNavigationDelegate {

return task
}
// swiftlint:enable function_parameter_count

func makeAsyncDecision<T>(for actionDebugInfo: some CustomDebugStringConvertible,
boundToLifetimeOf webView: WKWebView,
Expand Down Expand Up @@ -310,8 +308,7 @@ extension DistributedNavigationDelegate: WKNavigationDelegate {
// MARK: Policy making

@MainActor
// swiftlint:disable function_body_length
// swiftlint:disable cyclomatic_complexity
// swiftlint:disable:next cyclomatic_complexity
public func webView(_ webView: WKWebView, decidePolicyFor wkNavigationAction: WKNavigationAction, preferences wkPreferences: WKWebpagePreferences, decisionHandler: @escaping (WKNavigationActionPolicy, WKWebpagePreferences) -> Void) {

// new navigation or an ongoing navigation (for a server-redirect)?
Expand Down Expand Up @@ -432,8 +429,6 @@ extension DistributedNavigationDelegate: WKNavigationDelegate {
self.navigationActionDecisionTask = task
}
}
// swiftlint:enable function_body_length
// swiftlint:enable cyclomatic_complexity

@MainActor
private func willStart(_ navigation: Navigation) {
Expand Down Expand Up @@ -643,10 +638,9 @@ extension DistributedNavigationDelegate: WKNavigationDelegate {

#if WILLPERFORMCLIENTREDIRECT_ENABLED

// swiftlint:disable function_body_length
// swiftlint:disable cyclomatic_complexity
@MainActor
@objc(_webView:willPerformClientRedirectToURL:delay:)
// swiftlint:disable:next cyclomatic_complexity
public func webView(_ webView: WKWebView, willPerformClientRedirectTo url: URL, delay: TimeInterval) {
for responder in responders {
responder.webViewWillPerformClientRedirect(to: url, withDelay: delay)
Expand Down Expand Up @@ -742,8 +736,6 @@ extension DistributedNavigationDelegate: WKNavigationDelegate {
// set Navigation state to .redirected and expect the redirect NavigationAction
redirectedNavigation.willPerformClientRedirect(to: url, delay: delay)
}
// swiftlint:enable function_body_length
// swiftlint:enable cyclomatic_complexity

@MainActor
@objc(_webViewDidCancelClientRedirect:)
Expand Down
1 change: 0 additions & 1 deletion Sources/Navigation/NavigationState.swift
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ public enum NavigationState: Equatable, Comparable {
isFinished || isFailed
}

// swiftlint:disable:next cyclomatic_complexity
public static func == (lhs: NavigationState, rhs: NavigationState) -> Bool {
switch lhs {
case .expected(let navigationType): if case .expected(navigationType) = rhs { return true }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public enum ExtensionMessage: RawRepresentable {
case simulateConnectionInterruption
case getDataVolume

// swiftlint:disable:next cyclomatic_complexity function_body_length
public init?(rawValue data: Data) {
let name = data.first.flatMap(Name.init(rawValue:))
switch name {
Expand Down
Loading
Loading