Skip to content

Commit

Permalink
chore(geo): resolve swiftformat errors and warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
phantumcode committed Sep 3, 2024
1 parent ca6c65a commit baa308c
Show file tree
Hide file tree
Showing 21 changed files with 108 additions and 103 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

import AWSLocation

extension AWSLocationGeoPlugin {
public extension AWSLocationGeoPlugin {

// MARK: - Search

Expand All @@ -30,8 +30,9 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func search(for text: String,
options: Geo.SearchForTextOptions? = nil) async throws -> [Geo.Place] {
func search(for text: String,
options: Geo.SearchForTextOptions? = nil) async throws -> [Geo.Place]
{

Check failure on line 35 in AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)

var request = SearchPlaceIndexForTextInput()

Expand Down Expand Up @@ -73,9 +74,7 @@ extension AWSLocationGeoPlugin {
let response = try await locationService.searchPlaceIndex(forText: request)
var results = [LocationClientTypes.Place]()
if let responseResults = response.results {
results = responseResults.compactMap {
$0.place
}
results = responseResults.compactMap(\.place)
}

let places: [Geo.Place] = results.compactMap {
Expand Down Expand Up @@ -123,8 +122,9 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func search(for coordinates: Geo.Coordinates,
options: Geo.SearchForCoordinatesOptions? = nil) async throws -> [Geo.Place] {
func search(for coordinates: Geo.Coordinates,
options: Geo.SearchForCoordinatesOptions? = nil) async throws -> [Geo.Place]
{

Check failure on line 127 in AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+ClientBehavior.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)

var request = SearchPlaceIndexForPositionInput()

Expand All @@ -148,9 +148,7 @@ extension AWSLocationGeoPlugin {
let response = try await locationService.searchPlaceIndex(forPosition: request)
var results = [LocationClientTypes.Place]()
if let responseResults = response.results {
results = responseResults.compactMap {
$0.place
}
results = responseResults.compactMap(\.place)
}

let places: [Geo.Place] = results.compactMap {
Expand Down Expand Up @@ -194,7 +192,7 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func availableMaps() async throws -> [Geo.MapStyle] {
func availableMaps() async throws -> [Geo.MapStyle] {
let mapStyles = Array(pluginConfig.maps.values)
guard !mapStyles.isEmpty else {
throw Geo.Error.invalidConfiguration(
Expand All @@ -213,7 +211,7 @@ extension AWSLocationGeoPlugin {
/// `Geo.Error.networkError` if request failed or network unavailable
/// `Geo.Error.pluginError` if encapsulated error received by a dependent plugin
/// `Geo.Error.unknown` if error is unknown
public func defaultMap() async throws -> Geo.MapStyle {
func defaultMap() async throws -> Geo.MapStyle {
guard let mapName = pluginConfig.defaultMap, let mapStyle = pluginConfig.maps[mapName] else {
throw Geo.Error.invalidConfiguration(
GeoPluginErrorConstants.missingDefaultMap.errorDescription,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,20 @@

import Foundation
@_spi(InternalAmplifyConfiguration) import Amplify
import AWSClientRuntime
import AWSLocation
import AWSPluginsCore
@_spi(PluginHTTPClientEngine) import InternalAmplifyCredentials
import AWSLocation
import AWSClientRuntime

extension AWSLocationGeoPlugin {
public extension AWSLocationGeoPlugin {
/// Configures AWSLocationPlugin with the specified configuration.
///
/// This method will be invoked as part of the Amplify configuration flow.
///
/// - Parameter configuration: The configuration specified for this plugin.
/// - Throws:
/// - PluginError.pluginConfigurationError: If one of the configuration values is invalid or empty.
public func configure(using configuration: Any?) throws {
func configure(using configuration: Any?) throws {
let pluginConfiguration: AWSLocationGeoPluginConfiguration
if let configuration = configuration as? AmplifyOutputsData {
pluginConfiguration = try AWSLocationGeoPluginConfiguration(config: configuration)
Expand All @@ -34,7 +34,7 @@ extension AWSLocationGeoPlugin {
}

/// Configure AWSLocationPlugin programatically using AWSLocationPluginConfiguration
public func configure(using configuration: AWSLocationGeoPluginConfiguration) throws {
func configure(using configuration: AWSLocationGeoPluginConfiguration) throws {
let authService = AWSAuthService()
let credentialsProvider = authService.getCredentialsProvider()
let region = configuration.regionName
Expand Down Expand Up @@ -64,9 +64,10 @@ extension AWSLocationGeoPlugin {
/// - locationService: The location service object.
/// - authService: The authentication service object.
/// - pluginConfig: The configuration for the plugin.
func configure(locationService: AWSLocationBehavior,
internal func configure(locationService: AWSLocationBehavior,
authService: AWSAuthServiceBehavior,
pluginConfig: AWSLocationGeoPluginConfiguration) {
pluginConfig: AWSLocationGeoPluginConfiguration)
{

Check failure on line 70 in AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/AWSLocationGeoPlugin+Configure.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.locationService = locationService
self.authService = authService
self.pluginConfig = pluginConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
import Amplify
import Foundation

extension AWSLocationGeoPlugin {
public extension AWSLocationGeoPlugin {

/// Resets the state of the plugin.
///
/// Sets stored objects to nil to allow deallocation, then calls onComplete closure
/// to signal the reset has completed.
public func reset() async {
func reset() async {
locationService = nil
authService = nil
pluginConfig = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

@_spi(InternalAmplifyConfiguration) import Amplify
import Foundation
import AWSLocation
import Foundation

public struct AWSLocationGeoPluginConfiguration {
private static func urlString(regionName: String, mapName: String) -> String {
Expand Down Expand Up @@ -60,7 +60,7 @@ public struct AWSLocationGeoPluginConfiguration {
defaultSearchIndex: defaultSearchIndex,
searchIndices: searchIndices)
}

init(config: AmplifyOutputsData) throws {
guard let geo = config.geo else {
throw GeoPluginConfigError.configurationInvalid(section: .plugin)
Expand Down Expand Up @@ -102,7 +102,8 @@ public struct AWSLocationGeoPluginConfiguration {
defaultMap: String?,
maps: [String: Geo.MapStyle],
defaultSearchIndex: String?,
searchIndices: [String]) {
searchIndices: [String])
{

Check failure on line 106 in AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
self.regionName = regionName
self.defaultMap = defaultMap
self.maps = maps
Expand Down Expand Up @@ -163,7 +164,8 @@ public struct AWSLocationGeoPluginConfiguration {
}

private static func getItemsObject(section: Section,
configObject: [String: JSONValue]) throws -> [String: JSONValue] {
configObject: [String: JSONValue]) throws -> [String: JSONValue]
{

Check failure on line 168 in AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
let itemsJSON = try getItemsJSON(section: section, configObject: configObject)
let itemsObject = try getConfigObject(section: section, configJSON: itemsJSON)
return itemsObject
Expand Down Expand Up @@ -216,7 +218,8 @@ public struct AWSLocationGeoPluginConfiguration {
}

private static func getMaps(mapConfig: AmplifyOutputsData.Geo.Maps,
regionName: String) throws -> [String: Geo.MapStyle] {
regionName: String) throws -> [String: Geo.MapStyle]
{

Check failure on line 222 in AmplifyPlugins/Geo/Sources/AWSLocationGeoPlugin/Configuration/AWSLocationGeoPluginConfiguration.swift

View workflow job for this annotation

GitHub Actions / run-swiftlint

Opening braces should be preceded by a single space and on the same line as the declaration (opening_brace)
let mapTuples: [(String, Geo.MapStyle)] = try mapConfig.items.map { map in
let url = URL(string: AWSLocationGeoPluginConfiguration.urlString(regionName: regionName,
mapName: map.key))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import Foundation

typealias GeoPluginErrorString = (errorDescription: ErrorDescription, recoverySuggestion: RecoverySuggestion)

struct GeoPluginConfigError {
enum GeoPluginConfigError {
static func configurationInvalid(section: AWSLocationGeoPluginConfiguration.Section) -> PluginError {
PluginError.pluginConfigurationError(
"Unable to decode \(section.key) configuration.",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import AWSLocation
import Foundation

/// Behavior that `AWSLocationAdapter` will use.
/// This protocol allows a way to create a Mock and ensure the plugin implementation is testable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
// SPDX-License-Identifier: Apache-2.0
//

import Foundation
import Amplify
import Foundation

struct GeoPluginErrorConstants {
enum GeoPluginErrorConstants {
static let missingDefaultSearchIndex: GeoPluginErrorString = (
"No default search index was found.",
"Please ensure you have added search to your project before calling search functions.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
//

import Amplify
import Foundation
import AWSLocation
import AWSClientRuntime
import AWSLocation
import Foundation

protocol GeoErrorConvertible {
var geoError: Geo.Error { get }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
import AWSLocationGeoPlugin
import XCTest

// swiftlint:disable:next type_name
class AWSLocationGeoPluginAmplifyVersionableTests: XCTestCase {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import Amplify
import AWSLocation
@testable import AWSLocationGeoPlugin
import XCTest
@testable import AWSLocationGeoPlugin

class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase {
let searchText = "coffee shop"
Expand All @@ -28,8 +28,8 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase {
do {
_ = try await geoPlugin.search(for: searchText, options: nil)
var request = SearchPlaceIndexForTextInput()
request.text = self.searchText
self.mockLocation.verifySearchPlaceIndexForText(request)
request.text = searchText
mockLocation.verifySearchPlaceIndexForText(request)
} catch {
XCTFail("Failed with error: \(error)")
}
Expand All @@ -53,13 +53,13 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase {
do {
_ = try await geoPlugin.search(for: searchText, options: options)
var request = SearchPlaceIndexForTextInput()
request.text = self.searchText
request.biasPosition = [(self.coordinates.longitude),
(self.coordinates.latitude)]
request.filterCountries = options.countries?.map { $0.code }
request.text = searchText
request.biasPosition = [coordinates.longitude,
coordinates.latitude]
request.filterCountries = options.countries?.map(\.code)
request.maxResults = options.maxResults ?? 0
request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex
self.mockLocation.verifySearchPlaceIndexForText(request)
mockLocation.verifySearchPlaceIndexForText(request)
} catch {
XCTFail("Failed with error: \(error)")
}
Expand Down Expand Up @@ -100,9 +100,9 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase {
do {
_ = try await geoPlugin.search(for: coordinates, options: nil)
var request = SearchPlaceIndexForPositionInput()
request.position = [(self.coordinates.longitude),
(self.coordinates.latitude)]
self.mockLocation.verifySearchPlaceIndexForPosition(request)
request.position = [coordinates.longitude,
coordinates.latitude]
mockLocation.verifySearchPlaceIndexForPosition(request)
} catch {
XCTFail("Failed with error: \(error)")
}
Expand All @@ -124,11 +124,11 @@ class AWSLocationGeoPluginClientBehaviorTests: AWSLocationGeoPluginTestBase {
do {
_ = try await geoPlugin.search(for: coordinates, options: options)
var request = SearchPlaceIndexForPositionInput()
request.position = [(self.coordinates.longitude),
(self.coordinates.latitude) ]
request.position = [coordinates.longitude,
coordinates.latitude]
request.maxResults = options.maxResults ?? 0
request.indexName = (options.pluginOptions as? AWSLocationGeoPluginSearchOptions)?.searchIndex
self.mockLocation.verifySearchPlaceIndexForPosition(request)
mockLocation.verifySearchPlaceIndexForPosition(request)
} catch {
XCTFail("Failed with error: \(error)")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import Amplify
@testable import AWSLocationGeoPlugin
import XCTest
@testable import AWSLocationGeoPlugin

class AWSLocationGeoPluginConfigureTests: AWSLocationGeoPluginTestBase {
// MARK: - Plugin Key test
Expand Down Expand Up @@ -56,7 +56,8 @@ class AWSLocationGeoPluginConfigureTests: AWSLocationGeoPluginTestBase {
XCTFail("Geo configuration should not succeed.")
} catch {
guard let pluginError = error as? PluginError,
case .pluginConfigurationError = pluginError else {
case .pluginConfigurationError = pluginError
else {
XCTFail("Should throw invalidConfiguration exception. But received \(error) ")
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@
//

import Amplify
@testable import AWSLocationGeoPlugin
import XCTest
@testable import AWSLocationGeoPlugin

class AWSLocationGeoPluginResetTests: AWSLocationGeoPluginTestBase {
func testReset() async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
// SPDX-License-Identifier: Apache-2.0
//

import XCTest
@testable import Amplify
@testable import AmplifyTestCommon
@testable import AWSLocationGeoPlugin
@testable import AWSPluginsTestCommon
import XCTest

class AWSLocationGeoPluginTestBase: XCTestCase {
var geoPlugin: AWSLocationGeoPlugin!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
// SPDX-License-Identifier: Apache-2.0
//

@testable @_spi(InternalAmplifyConfiguration) import Amplify
import XCTest
@testable @_spi(InternalAmplifyConfiguration) import Amplify

@testable import AWSLocationGeoPlugin

Expand Down
Loading

0 comments on commit baa308c

Please sign in to comment.