Skip to content

Commit

Permalink
chore(linter/swift): add shorthand_optional_binding rule (#3456)
Browse files Browse the repository at this point in the history
* chore(linter/swift): add `shorthand_optional_binding` rule

* lint code
  • Loading branch information
KrzysztofMoch authored Jan 4, 2024
1 parent 481cc71 commit 2ed3949
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 55 deletions.
1 change: 1 addition & 0 deletions ios/.swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ opt_in_rules:
- redundant_nil_coalescing
- attributes
- convenience_type
- shorthand_optional_binding
analyzer_rules:
- explicit_self
- unused_declaration
Expand Down
8 changes: 4 additions & 4 deletions ios/Video/Features/RCTIMAAdsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
}

func requestAds() {
guard let _video = _video else { return }
guard let _video else { return }
// Create ad display container for ad rendering.
let adDisplayContainer = IMAAdDisplayContainer(adContainer: _video, viewController: _video.reactViewController())

Expand Down Expand Up @@ -57,7 +57,7 @@
// MARK: - IMAAdsLoaderDelegate

func adsLoader(_: IMAAdsLoader, adsLoadedWith adsLoadedData: IMAAdsLoadedData) {
guard let _video = _video else { return }
guard let _video else { return }
// Grab the instance of the IMAAdsManager and set yourself as the delegate.
adsManager = adsLoadedData.adsManager
adsManager?.delegate = self
Expand All @@ -81,7 +81,7 @@
// MARK: - IMAAdsManagerDelegate

func adsManager(_ adsManager: IMAAdsManager, didReceive event: IMAAdEvent) {
guard let _video = _video else { return }
guard let _video else { return }
// Mute ad if the main player is muted
if _video.isMuted() {
adsManager.volume = 0
Expand Down Expand Up @@ -117,7 +117,7 @@
print("AdsManager error: " + error.message!)
}

guard let _video = _video else { return }
guard let _video else { return }

if _video.onReceiveAdEvent != nil {
_video.onReceiveAdEvent?([
Expand Down
10 changes: 5 additions & 5 deletions ios/Video/Features/RCTPictureInPicture.swift
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import React
}

func pictureInPictureControllerDidStartPictureInPicture(_: AVPictureInPictureController) {
guard let _onPictureInPictureStatusChanged = _onPictureInPictureStatusChanged else { return }
guard let _onPictureInPictureStatusChanged else { return }

_onPictureInPictureStatusChanged()
}

func pictureInPictureControllerDidStopPictureInPicture(_: AVPictureInPictureController) {
guard let _onPictureInPictureStatusChanged = _onPictureInPictureStatusChanged else { return }
guard let _onPictureInPictureStatusChanged else { return }

_onPictureInPictureStatusChanged()
}
Expand All @@ -33,15 +33,15 @@ import React
_: AVPictureInPictureController,
restoreUserInterfaceForPictureInPictureStopWithCompletionHandler completionHandler: @escaping (Bool) -> Void
) {
guard let _onRestoreUserInterfaceForPictureInPictureStop = _onRestoreUserInterfaceForPictureInPictureStop else { return }
guard let _onRestoreUserInterfaceForPictureInPictureStop else { return }

_onRestoreUserInterfaceForPictureInPictureStop()

_restoreUserInterfaceForPIPStopCompletionHandler = completionHandler
}

func setRestoreUserInterfaceForPIPStopCompletionHandler(_ restore: Bool) {
guard let _restoreUserInterfaceForPIPStopCompletionHandler = _restoreUserInterfaceForPIPStopCompletionHandler else { return }
guard let _restoreUserInterfaceForPIPStopCompletionHandler else { return }
_restoreUserInterfaceForPIPStopCompletionHandler(restore)
self._restoreUserInterfaceForPIPStopCompletionHandler = nil
}
Expand All @@ -61,7 +61,7 @@ import React
}
_isActive = isActive

guard let _pipController = _pipController else { return }
guard let _pipController else { return }

if _isActive && !_pipController.isPictureInPictureActive {
DispatchQueue.main.async {
Expand Down
4 changes: 2 additions & 2 deletions ios/Video/Features/RCTPlayerObserver.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate {
private var _playerViewControllerOverlayFrameObserver: NSKeyValueObservation?

deinit {
if let _handlers = _handlers {
if let _handlers {
NotificationCenter.default.removeObserver(_handlers)
}
}
Expand Down Expand Up @@ -206,7 +206,7 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate {
}

func replaceTimeObserverIfSet(_ newUpdateInterval: Float64? = nil) {
if let newUpdateInterval = newUpdateInterval {
if let newUpdateInterval {
_progressUpdateInterval = newUpdateInterval
}
if _timeObserver != nil {
Expand Down
10 changes: 5 additions & 5 deletions ios/Video/Features/RCTPlayerOperations.swift
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,12 @@ enum RCTPlayerOperations {
mediaOption = group.options[index]
}
}
} else if let group = group { // default. invalid type or "system"
} else if let group { // default. invalid type or "system"
player?.currentItem?.selectMediaOptionAutomatically(in: group)
return
}

if let group = group {
if let group {
// If a match isn't found, option will be nil and text tracks will be disabled
player?.currentItem?.select(mediaOption, in: group)
}
Expand Down Expand Up @@ -206,7 +206,7 @@ enum RCTPlayerOperations {
options = .duckOthers
}

if let category = category, let options = options {
if let category, let options {
do {
try audioSession.setCategory(category, options: options)
} catch {
Expand All @@ -229,13 +229,13 @@ enum RCTPlayerOperations {
}
#endif
}
} else if let category = category, options == nil {
} else if let category, options == nil {
do {
try audioSession.setCategory(category)
} catch {
debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession category. Error: \(error).")
}
} else if category == nil, let options = options {
} else if category == nil, let options {
do {
try audioSession.setCategory(audioSession.category, options: options)
} catch {
Expand Down
4 changes: 2 additions & 2 deletions ios/Video/Features/RCTResourceLoaderDelegate.swift
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes

func handleEmbeddedKey(_ loadingRequest: AVAssetResourceLoadingRequest!) -> Bool {
guard let url = loadingRequest.request.url,
let _localSourceEncryptionKeyScheme = _localSourceEncryptionKeyScheme,
let _localSourceEncryptionKeyScheme,
let persistentKeyData = RCTVideoUtils.extractDataFromCustomSchemeUrl(from: url, scheme: _localSourceEncryptionKeyScheme)
else {
return false
Expand All @@ -139,7 +139,7 @@ class RCTResourceLoaderDelegate: NSObject, AVAssetResourceLoaderDelegate, URLSes

_loadingRequests[requestKey] = loadingRequest

guard let _drm = _drm, let drmType = _drm.type, drmType == "fairplay" else {
guard let _drm, let drmType = _drm.type, drmType == "fairplay" else {
return finishLoadingWithError(error: RCTVideoErrorHandler.noDRMData, licenseUrl: requestKey)
}

Expand Down
12 changes: 6 additions & 6 deletions ios/Video/Features/RCTVideoDRM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ enum RCTVideoDRM {
var request = URLRequest(url: URL(string: licenseServer)!)
request.httpMethod = "POST"

if let headers = headers {
if let headers {
for item in headers {
guard let key = item.key as? String, let value = item.value as? String else {
continue
Expand Down Expand Up @@ -90,7 +90,7 @@ enum RCTVideoDRM {
reject(spcError)
}

guard let spcData = spcData else {
guard let spcData else {
reject(RCTVideoErrorHandler.noSPC)
return
}
Expand All @@ -101,7 +101,7 @@ enum RCTVideoDRM {

static func createCertificateData(certificateStringUrl: String?, base64Certificate: Bool?) -> Promise<Data> {
return Promise<Data>(on: .global()) { fulfill, reject in
guard let certificateStringUrl = certificateStringUrl,
guard let certificateStringUrl,
let certificateURL = URL(string: certificateStringUrl.addingPercentEncoding(withAllowedCharacters: .urlFragmentAllowed) ?? "") else {
reject(RCTVideoErrorHandler.noCertificateURL)
return
Expand All @@ -115,7 +115,7 @@ enum RCTVideoDRM {
}
} catch {}

guard let certificateData = certificateData else {
guard let certificateData else {
reject(RCTVideoErrorHandler.noCertificateData)
return
}
Expand All @@ -130,7 +130,7 @@ enum RCTVideoDRM {

return RCTVideoDRM.createCertificateData(certificateStringUrl: certificateUrl, base64Certificate: base64Certificate)
.then { certificateData -> Promise<Data> in
guard let contentIdData = contentIdData else {
guard let contentIdData else {
throw RCTVideoError.invalidContentId as! Error
}

Expand Down Expand Up @@ -167,7 +167,7 @@ enum RCTVideoDRM {
)
}
.then { spcData -> Promise<Data> in
guard let licenseServer = licenseServer else {
guard let licenseServer else {
throw RCTVideoError.noLicenseServerURL as! Error
}
return RCTVideoDRM.fetchLicense(
Expand Down
12 changes: 6 additions & 6 deletions ios/Video/Features/RCTVideoUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ enum RCTVideoUtils {
* \returns The playable duration of the current player item in seconds.
*/
static func calculatePlayableDuration(_ player: AVPlayer?, withSource source: VideoSource?) -> NSNumber {
guard let player = player,
guard let player,
let video: AVPlayerItem = player.currentItem,
video.status == AVPlayerItem.Status.readyToPlay else {
return 0
Expand All @@ -31,7 +31,7 @@ enum RCTVideoUtils {
}
}

if let effectiveTimeRange = effectiveTimeRange {
if let effectiveTimeRange {
let playableDuration: Float64 = CMTimeGetSeconds(CMTimeRangeGetEnd(effectiveTimeRange))
if playableDuration > 0 {
if source?.cropStart != nil {
Expand Down Expand Up @@ -95,7 +95,7 @@ enum RCTVideoUtils {
}

static func getAudioTrackInfo(_ player: AVPlayer?) -> [AnyObject]! {
guard let player = player else {
guard let player else {
return []
}

Expand Down Expand Up @@ -124,7 +124,7 @@ enum RCTVideoUtils {
}

static func getTextTrackInfo(_ player: AVPlayer?) -> [TextTrack]! {
guard let player = player else {
guard let player else {
return []
}

Expand Down Expand Up @@ -158,7 +158,7 @@ enum RCTVideoUtils {
}

static func base64DataFromBase64String(base64String: String?) -> Data? {
if let base64String = base64String {
if let base64String {
return Data(base64Encoded: base64String)
}
return nil
Expand Down Expand Up @@ -216,7 +216,7 @@ enum RCTVideoUtils {
let videoAsset: AVAssetTrack! = asset.tracks(withMediaType: AVMediaType.video).first
var validTextTracks: [TextTrack] = []

if let textTracks = textTracks, !textTracks.isEmpty {
if let textTracks, !textTracks.isEmpty {
for i in 0 ..< textTracks.count {
var textURLAsset: AVURLAsset!
let textUri: String = textTracks[i].uri
Expand Down
Loading

0 comments on commit 2ed3949

Please sign in to comment.