Skip to content

Commit 130c5f6

Browse files
authored
style: add swiftformat
2 parents 754df51 + df5a1cb commit 130c5f6

9 files changed

Lines changed: 104 additions & 87 deletions

ios/.swiftformat

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--swiftversion 5.10
2+
--disable conditionalAssignment
3+
--disable redundantType
4+
--disable unusedArguments
5+
--binary-grouping none
6+
--decimal-grouping none
7+
--hex-literal-case lowercase
8+
--indent 2
9+
--no-space-operators
10+
--semicolons never
11+
--trailing-commas never
12+
--rules braces,indent
13+
--wrap-arguments preserve
14+
--wrap-parameters preserve
15+
--wrap-collections preserve
16+
--closing-paren same-line
17+
--xcode-indentation enabled

ios/Color.swift

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -41,17 +41,17 @@ extension UIColor {
4141
private static func fromRGBFunction(_ s: String) -> UIColor? {
4242
let nums =
4343
s
44-
.replacingOccurrences(of: "rgba", with: "")
45-
.replacingOccurrences(of: "rgb", with: "")
46-
.replacingOccurrences(of: "(", with: "")
47-
.replacingOccurrences(of: ")", with: "")
48-
.split(separator: ",")
49-
.map { $0.trimmingCharacters(in: .whitespaces) }
44+
.replacingOccurrences(of: "rgba", with: "")
45+
.replacingOccurrences(of: "rgb", with: "")
46+
.replacingOccurrences(of: "(", with: "")
47+
.replacingOccurrences(of: ")", with: "")
48+
.split(separator: ",")
49+
.map { $0.trimmingCharacters(in: .whitespaces) }
5050

5151
guard nums.count == 3 || nums.count == 4,
52-
let r = Double(nums[0]),
53-
let g = Double(nums[1]),
54-
let b = Double(nums[2])
52+
let r = Double(nums[0]),
53+
let g = Double(nums[1]),
54+
let b = Double(nums[2])
5555
else { return nil }
5656
let a = (nums.count == 4) ? (Double(nums[3]) ?? 1.0) : 1.0
5757
return UIColor(
@@ -65,18 +65,18 @@ extension UIColor {
6565
private static func fromHSLFunction(_ s: String) -> UIColor? {
6666
let parts =
6767
s
68-
.replacingOccurrences(of: "hsla", with: "")
69-
.replacingOccurrences(of: "hsl", with: "")
70-
.replacingOccurrences(of: "(", with: "")
71-
.replacingOccurrences(of: ")", with: "")
72-
.replacingOccurrences(of: "%", with: "")
73-
.split(separator: ",")
74-
.map { $0.trimmingCharacters(in: .whitespaces) }
68+
.replacingOccurrences(of: "hsla", with: "")
69+
.replacingOccurrences(of: "hsl", with: "")
70+
.replacingOccurrences(of: "(", with: "")
71+
.replacingOccurrences(of: ")", with: "")
72+
.replacingOccurrences(of: "%", with: "")
73+
.split(separator: ",")
74+
.map { $0.trimmingCharacters(in: .whitespaces) }
7575

7676
guard parts.count == 3 || parts.count == 4,
77-
let h = Double(parts[0]),
78-
let sPerc = Double(parts[1]),
79-
let lPerc = Double(parts[2])
77+
let h = Double(parts[0]),
78+
let sPerc = Double(parts[1]),
79+
let lPerc = Double(parts[2])
8080
else { return nil }
8181

8282
let a = (parts.count == 4) ? (Double(parts[3]) ?? 1.0) : 1.0
@@ -87,7 +87,7 @@ extension UIColor {
8787
let x = c * (1 - Swift.abs((h / 60).truncatingRemainder(dividingBy: 2) - 1))
8888
let m = l - c / 2
8989

90-
// swiftlint:disable:next large_tuple
90+
// swiftlint:disable:next large_tuple
9191
let (r1, g1, b1): (Double, Double, Double)
9292
switch h {
9393
case 0..<60: (r1, g1, b1) = (c, x, 0)

ios/GoogleMapViewImpl.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
9797
if self.lastSubmittedLocation?.coordinate.latitude
9898
!= loc.coordinate.latitude
9999
|| self.lastSubmittedLocation?.coordinate.longitude
100-
!= loc.coordinate.longitude {
100+
!= loc.coordinate.longitude {
101101
self.onLocationUpdate?(
102102
RNLocation(
103103
RNLatLng(
@@ -120,36 +120,36 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
120120
private func applyPending() {
121121

122122
if let padding = pendingMapPadding {
123-
mapView.padding = UIEdgeInsets(
124-
top: padding.top,
125-
left: padding.left,
126-
bottom: padding.bottom,
127-
right: padding.right
128-
)
123+
mapView.padding = UIEdgeInsets(
124+
top: padding.top,
125+
left: padding.left,
126+
bottom: padding.bottom,
127+
right: padding.right
128+
)
129129
}
130130

131131
if let style = pendingCustomMapStyle {
132-
mapView.mapStyle = style
132+
mapView.mapStyle = style
133133
}
134134

135135
if let mapType = pendingMapType {
136-
mapView.mapType = mapType
136+
mapView.mapType = mapType
137137
}
138138

139139
if let buildings = pendingBuildingEnabled {
140-
mapView.isBuildingsEnabled = buildings
140+
mapView.isBuildingsEnabled = buildings
141141
}
142142

143143
if let traffic = pendingTrafficEnabled {
144-
mapView.isTrafficEnabled = traffic
144+
mapView.isTrafficEnabled = traffic
145145
}
146146

147147
if let uiStyle = pendingUserInterfaceStyle {
148-
mapView.overrideUserInterfaceStyle = uiStyle
148+
mapView.overrideUserInterfaceStyle = uiStyle
149149
}
150150

151151
if let minZoom = pendingMinZoomLevel, let maxZoom = pendingMaxZoomLevel {
152-
mapView.setMinZoom(Float(minZoom), maxZoom: Float(maxZoom))
152+
mapView.setMinZoom(Float(minZoom), maxZoom: Float(maxZoom))
153153
}
154154

155155
if !pendingMarkers.isEmpty {
@@ -260,10 +260,10 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
260260
pendingMapPadding = newValue
261261
if let padding = newValue {
262262
mapView.padding = UIEdgeInsets(
263-
top: padding.top,
264-
left: padding.left,
265-
bottom: padding.bottom,
266-
right: padding.right
263+
top: padding.top,
264+
left: padding.left,
265+
bottom: padding.bottom,
266+
right: padding.right
267267
)
268268
} else {
269269
mapView.padding = .zero
@@ -494,7 +494,7 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
494494
super.didMoveToWindow()
495495
if window != nil {
496496
if mapView != nil && mapReady {
497-
onMapReady?(true)
497+
onMapReady?(true)
498498
}
499499
locationHandler.start()
500500
} else {
@@ -541,11 +541,11 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
541541

542542
func mapView(_ mapView: GMSMapView, didChange position: GMSCameraPosition) {
543543
if let last = lastSubmittedCameraPosition,
544-
last.target.latitude == position.target.latitude,
545-
last.target.longitude == position.target.longitude,
546-
last.zoom == position.zoom,
547-
last.bearing == position.bearing,
548-
last.viewingAngle == position.viewingAngle {
544+
last.target.latitude == position.target.latitude,
545+
last.target.longitude == position.target.longitude,
546+
last.zoom == position.zoom,
547+
last.bearing == position.bearing,
548+
last.viewingAngle == position.viewingAngle {
549549
return
550550
}
551551
let visibleRegion = mapView.projection.visibleRegion()
@@ -613,10 +613,10 @@ final class GoogleMapsViewImpl: UIView, GMSMapViewDelegate {
613613
didTapAt coordinate: CLLocationCoordinate2D
614614
) {
615615
onMapPress?(
616-
RNLatLng(
617-
latitude: coordinate.latitude,
618-
longitude: coordinate.longitude
619-
))
616+
RNLatLng(
617+
latitude: coordinate.latitude,
618+
longitude: coordinate.longitude
619+
))
620620
}
621621

622622
func mapView(_ mapView: GMSMapView, didTap marker: GMSMarker) -> Bool {

ios/MapPolygon.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ extension RNPolygon {
3939

4040
func polygonEquals(_ b: RNPolygon) -> Bool {
4141
guard zIndex == b.zIndex,
42-
strokeWidth == b.strokeWidth,
43-
fillColor == b.fillColor,
44-
strokeColor == b.strokeColor,
45-
coordinates.count == b.coordinates.count
42+
strokeWidth == b.strokeWidth,
43+
fillColor == b.fillColor,
44+
strokeColor == b.strokeColor,
45+
coordinates.count == b.coordinates.count
4646
else { return false }
4747
for i in 0..<coordinates.count {
4848
if coordinates[i].latitude != b.coordinates[i].latitude

ios/MapPolyline.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,11 @@ extension RNPolyline {
6666

6767
func polylineEquals(_ b: RNPolyline) -> Bool {
6868
guard zIndex == b.zIndex,
69-
(width ?? 0) == (b.width ?? 0),
70-
lineCap == b.lineCap,
71-
lineJoin == b.lineJoin,
72-
color == b.color,
73-
coordinates.count == b.coordinates.count
69+
(width ?? 0) == (b.width ?? 0),
70+
lineCap == b.lineCap,
71+
lineJoin == b.lineJoin,
72+
color == b.color,
73+
coordinates.count == b.coordinates.count
7474
else { return false }
7575
for i in 0..<coordinates.count {
7676
if coordinates[i].latitude != b.coordinates[i].latitude

ios/PermissionHandler.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ final class PermissionHandler: NSObject, CLLocationManagerDelegate {
1414
}
1515

1616
func requestLocationPermission()
17-
-> NitroModules.Promise<RNLocationPermissionResult> {
17+
-> NitroModules.Promise<RNLocationPermissionResult> {
1818
let promise = NitroModules.Promise<RNLocationPermissionResult>()
1919

2020
let status = manager.authorizationStatus

ios/RNGoogleMapsPlusModule.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ final class RNGoogleMapsPlusModule: HybridRNGoogleMapsPlusModuleSpec {
1616
}
1717

1818
func requestLocationPermission()
19-
-> NitroModules.Promise<RNLocationPermissionResult> {
19+
-> NitroModules.Promise<RNLocationPermissionResult> {
2020
return permissionHandler.requestLocationPermission()
2121
}
2222

ios/RNGoogleMapsPlusView.swift

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
268268
}
269269

270270
func requestLocationPermission()
271-
-> NitroModules.Promise<RNLocationPermissionResult> {
271+
-> NitroModules.Promise<RNLocationPermissionResult> {
272272
return permissionHandler.requestLocationPermission()
273273
}
274274

@@ -298,8 +298,8 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
298298
}
299299

300300
private func mapCameraPositionToCamera(_ cp: GMSCameraPosition?)
301-
-> RNCamera? {
302-
guard let cp = cp else { return nil }
301+
-> RNCamera? {
302+
guard let cp = cp else { return nil }
303303

304304
return RNCamera(
305305
center: RNLatLng(
@@ -313,35 +313,35 @@ final class RNGoogleMapsPlusView: HybridRNGoogleMapsPlusViewSpec {
313313
}
314314

315315
func mapUserInterfaceStyleToUIUserInterfaceStyle(
316-
_ style: RNUserInterfaceStyle?
316+
_ style: RNUserInterfaceStyle?
317317
) -> UIUserInterfaceStyle? {
318-
guard let style = style else { return nil }
319-
320-
switch style {
321-
case .light:
322-
return .light
323-
case .dark:
324-
return .dark
325-
case .default:
326-
return .unspecified
327-
}
318+
guard let style = style else { return nil }
319+
320+
switch style {
321+
case .light:
322+
return .light
323+
case .dark:
324+
return .dark
325+
case .default:
326+
return .unspecified
327+
}
328328
}
329329

330330
func mapUIUserInterfaceStyleToUserInterfaceStyle(
331-
_ uiStyle: UIUserInterfaceStyle?
331+
_ uiStyle: UIUserInterfaceStyle?
332332
) -> RNUserInterfaceStyle? {
333-
guard let uiStyle = uiStyle else { return nil }
334-
335-
switch uiStyle {
336-
case .light:
337-
return .light
338-
case .dark:
339-
return .dark
340-
case .unspecified:
341-
return .default
342-
@unknown default:
343-
return .default
344-
}
333+
guard let uiStyle = uiStyle else { return nil }
334+
335+
switch uiStyle {
336+
case .light:
337+
return .light
338+
case .dark:
339+
return .dark
340+
case .unspecified:
341+
return .default
342+
@unknown default:
343+
return .default
344+
}
345345
}
346346
}
347347

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
"lint": "yarn lint:js && yarn lint:android && yarn lint:ios",
1212
"lint:js": "eslint . --max-warnings 0 && yarn prettier --check .",
1313
"lint:android": "cd android && ktlint -F ./**/*.kt*",
14-
"lint:ios": "cd ios && swiftlint --quiet",
14+
"lint:ios": "cd ios && swiftlint --quiet && swiftformat . --lint",
1515
"format": "yarn format:js && yarn format:ios && yarn format:android",
1616
"format:js": "prettier --write .",
1717
"format:android": "cd android && ktlint --format ./**/*.kt*",
18-
"format:ios": "cd ios && swiftlint --quiet --fix",
18+
"format:ios": "cd ios && swiftformat .",
1919
"clean": "del-cli android/build example/android/build example/android/app/build example/ios/build lib",
2020
"test": "jest",
2121
"git:clean": "git clean -dfX",

0 commit comments

Comments
 (0)