Skip to content

Commit

Permalink
Refactor FXIOS-10205 [Swiftlint] Enable implicitly_unwrapped_optional…
Browse files Browse the repository at this point in the history
… rule but keep it disabled for test files using nested Swiftlint configurations (#24031)

* Enable implicitly_unwrapped_optional rule in swiftlint configuration

* Disable rule for test files using swiftlint nested configuration

* Disable rule for focus-ios using swiftlint nested config

* Resolve implicitly_unwrapped_optional violation in SampleComponentLibraryApp

* Resolve implicitly_unwrapped_optional violations in SampleBrowser
  • Loading branch information
tonell-m authored Jan 23, 2025
1 parent 859e30d commit 55b930a
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 13 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ only_rules: # Only enforce these rules, ignore all others
- accessibility_trait_for_button
- force_cast
- closure_body_length
- implicitly_unwrapped_optional

# These rules were originally opted into. Disabling for now to get
# Swiftlint up and running.
Expand Down
9 changes: 9 additions & 0 deletions BrowserKit/Tests/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Swiftlint configuration overloads that will be applied to all files
# in this folder and all its children recursively, unless another
# nested configuration takes over.
# https://github.com/realm/SwiftLint#nested-configurations.

disabled_rules:
# Many test use implicitly unwrapped optional properties that
# initialized in setUp and reset in tearDown.
- implicitly_unwrapped_optional
8 changes: 4 additions & 4 deletions SampleBrowser/SampleBrowser/Engine/EngineProvider.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import WebEngine

struct EngineProvider {
// We only have one session in the SampleBrowser
private(set) var session: EngineSession?
private(set) var session: EngineSession
let view: EngineView

init(engine: Engine = WKEngine.factory(),
sessionDependencies: EngineSessionDependencies? = nil) {
init?(engine: Engine = WKEngine.factory(),
sessionDependencies: EngineSessionDependencies? = nil) {
do {
session = try engine.createSession(dependencies: sessionDependencies)
} catch {
session = nil
return nil
}

view = engine.createView()
Expand Down
4 changes: 2 additions & 2 deletions SampleBrowser/SampleBrowser/SceneDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ import WebEngine

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
var engineProvider: EngineProvider = {
var engineProvider: EngineProvider? = {
let dependencies = EngineSessionDependencies(telemetryProxy: TelemetryHandler())
return EngineProvider(sessionDependencies: dependencies)
}()

func scene(_ scene: UIScene,
willConnectTo session: UISceneSession,
options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
guard let windowScene = (scene as? UIWindowScene), let engineProvider else { return }
let windowUUID = UUID()
let baseViewController = RootViewController(engineProvider: engineProvider, windowUUID: windowUUID)
window = UIWindow(windowScene: windowScene)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class BrowserViewController: UIViewController,
FindInPageHelperDelegate {
weak var navigationDelegate: NavigationDelegate?
private lazy var progressView: UIProgressView = .build { _ in }
private var engineSession: EngineSession!
private var engineSession: EngineSession
private var engineView: EngineView
private let urlFormatter: URLFormatter

Expand Down Expand Up @@ -203,7 +203,7 @@ class BrowserViewController: UIViewController,
guard let url = linkURL else { return nil }

let previewProvider: UIContextMenuContentPreviewProvider = {
let previewEngineProvider = EngineProvider()
guard let previewEngineProvider = EngineProvider() else { return nil }
let previewVC = BrowserViewController(engineProvider: previewEngineProvider)
previewVC.engineSession.load(url: url.absoluteString)
return previewVC
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ protocol SuggestionViewControllerDelegate: AnyObject {

class SuggestionViewController: UIViewController, UITableViewDelegate {
private var tableView: UITableView
private var dataSource: SuggestionDataSource!
private var dataSource: SuggestionDataSource?
private weak var delegate: SuggestionViewControllerDelegate?

private var gradientLayer: CAGradientLayer?
Expand Down Expand Up @@ -87,14 +87,14 @@ class SuggestionViewController: UIViewController, UITableViewDelegate {

func updateUI(for suggestions: [String]) {
tableView.isHidden = suggestions.isEmpty
dataSource.suggestions = suggestions
dataSource?.suggestions = suggestions
tableView.reloadData()
}

// MARK: - UITableViewDelegate

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let term = dataSource.suggestions[indexPath.row]
guard let term = dataSource?.suggestions[indexPath.row] else { return }
delegate?.tapOnSuggestion(term: term)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ class BottomSheetChildViewController: UIViewController, BottomSheetChild, Themea
label.numberOfLines = 0
}

private var heightConstraint: NSLayoutConstraint!

init(themeManager: ThemeManager = AppContainer.shared.resolve()) {
self.themeManager = themeManager
super.init(nibName: nil, bundle: nil)
Expand Down
9 changes: 9 additions & 0 deletions firefox-ios/firefox-ios-tests/Tests/.swiftlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Swiftlint configuration overloads that will be applied to all files
# in this folder and all its children recursively, unless another
# nested configuration takes over.
# https://github.com/realm/SwiftLint#nested-configurations.

disabled_rules:
# Many test use implicitly unwrapped optional properties that
# initialized in setUp and reset in tearDown.
- implicitly_unwrapped_optional
1 change: 1 addition & 0 deletions focus-ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ disabled_rules:
- attributes
- trailing_whitespace
- vertical_whitespace
- implicitly_unwrapped_optional

0 comments on commit 55b930a

Please sign in to comment.