False positive code smell in swift

My code is being warned of violating following rules:
swift:S1481
swift:S1854

While the code is not really violating any of these rules and the code smell is on the last line of my below code

        let coordinates = searchParameters.locations.compactMap(\.coordinate).uniqued().compactMap { $0.locationCoordinate() }
        var cameraOptions: CameraOptions?
        if coordinates.count > 1 {
            cameraOptions = mapView.mapboxMap.camera(for: coordinates,
                                                     padding: Constants.padding,
                                                     bearing: mapView.mapboxMap.cameraState.bearing,
                                                     pitch: mapView.mapboxMap.cameraState.pitch)
        } else {
            guard let coordinate = coordinates.first else {
                logger.warn("coordinates is nil")
                return
            }
            cameraOptions = CameraOptions(center: coordinate,
                                          padding: Constants.padding,
                                          zoom: Country.current.mapSetupData.zoom * 1.8)
        }
        guard let cameraOptions = cameraOptions else { return }

Hi,

Thanks for bringing this to our attention. I created a ticket to improve this: SONARSWIFT-517 - False positive UnusedLocalVariable (S1481) and DeadStoreCheck (S1854) guard variable usages missing

Regards,
François

1 Like