Skip to content

Commit 18b3d0e

Browse files
persidskiygithub-actions[bot]
authored andcommitted
Fix Swiftlint in Maps iOS (#7829)
(cherry picked from commit d42b55e83e70ae351ca150e9b7dececc56e2170f) GitOrigin-RevId: 957e7d40200b9c82096b0e32b4521746dbd99768
1 parent c2f3f4d commit 18b3d0e

File tree

13 files changed

+60
-64
lines changed

13 files changed

+60
-64
lines changed

.swiftlint.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@ included:
55
- Tests
66
excluded:
77
- "**/Generated"
8+
- "Sources/Vendors/**"
89
disabled_rules:
910
- comment_spacing
1011
- computed_accessors_order
1112
- force_try
1213
- identifier_name
1314
- line_length
15+
- nesting
1416
- shorthand_operator
1517
- todo
1618
- trailing_comma

Sources/Examples/ExamplesSettingsView.swift

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ struct ClearableTextField: View {
1111
@Binding var text: String
1212
var keyboardType: UIKeyboardType = .default
1313
var autocapitalization: TextInputAutocapitalization = .never
14-
var focused: FocusState<Bool>.Binding? = nil
15-
var onSubmit: (() -> Void)? = nil
14+
var focused: FocusState<Bool>.Binding?
15+
var onSubmit: (() -> Void)?
1616

1717
var body: some View {
1818
HStack {
@@ -30,9 +30,9 @@ struct ClearableTextField: View {
3030
}
3131

3232
if !text.isEmpty {
33-
Button(action: {
33+
Button {
3434
text = ""
35-
}) {
35+
} label: {
3636
Image(systemName: "xmark.circle.fill")
3737
.foregroundColor(.secondary)
3838
}
@@ -174,12 +174,12 @@ struct StyleChooserView: View {
174174
}
175175
res += previouslyUsedURIs
176176
}
177-
177+
178178
for style in predefinedStyles {
179179
if res.contains(where: { $0.uri == style.uri }) { continue }
180180
res.append(style)
181181
}
182-
182+
183183
return res
184184
}
185185

@@ -205,9 +205,10 @@ struct StyleChooserView: View {
205205

206206
Section {
207207
ForEach(suggestions, id: \.uri) { suggestion in
208-
Button(action: {
208+
Button {
209209
customURL = suggestion.uri
210-
}) {
210+
}
211+
label: {
211212
HStack {
212213
VStack(alignment: .leading, spacing: 2) {
213214
if let name = suggestion.name {
@@ -312,9 +313,9 @@ struct StyleOverrideEditView: View {
312313
var body: some View {
313314
Form {
314315
Section {
315-
Button(action: {
316+
Button {
316317
showingBaseStyleChooser = true
317-
}) {
318+
} label: {
318319
if !baseStyle.isEmpty {
319320
Text(baseStyle)
320321
.monospaced()
@@ -328,9 +329,9 @@ struct StyleOverrideEditView: View {
328329
Text("This style will be replaced.")
329330
}
330331
Section {
331-
Button(action: {
332+
Button {
332333
showingReplacementStyleChooser = true
333-
}) {
334+
} label: {
334335
if !style.isEmpty {
335336
Text(style)
336337
.monospaced()
@@ -344,13 +345,12 @@ struct StyleOverrideEditView: View {
344345
Text("This style will be used instead.")
345346
}
346347

347-
348348
Section {
349349
ForEach(options) { keyValue in
350-
Button(action: {
350+
Button {
351351
editingConfigKey = keyValue.key
352352
showingConfigEditor = true
353-
}) {
353+
} label: {
354354
HStack( spacing: 2) {
355355
Text(keyValue.key)
356356
.foregroundColor(.primary)
@@ -366,10 +366,10 @@ struct StyleOverrideEditView: View {
366366
options.remove(atOffsets: indexSet)
367367
}
368368

369-
Button(action: {
369+
Button {
370370
editingConfigKey = nil
371371
showingConfigEditor = true
372-
}) {
372+
} label: {
373373
Text("Add")
374374
}
375375
} header: {
@@ -383,10 +383,10 @@ struct StyleOverrideEditView: View {
383383
Toggle("Active", isOn: $active)
384384

385385
if let onDelete {
386-
Button(action: {
386+
Button {
387387
onDelete()
388388
dismiss()
389-
}) {
389+
} label: {
390390
Text("Delete")
391391
.frame(maxWidth: .infinity)
392392
}

Sources/Examples/StyleOverridesModel.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class StyleOverridesModel: ObservableObject {
99
applyOverrides()
1010
}
1111
}
12-
12+
1313
@Published var previouslyUsedURIs: [String: Date] = [:] {
1414
didSet {
1515
savePreviouslyUsed()
1616
}
1717
}
18-
18+
1919
var activeCount: Int {
2020
overrides.filter { $0.active }.count
2121
}
@@ -33,13 +33,13 @@ class StyleOverridesModel: ObservableObject {
3333
userDefaults.set(encoded, forKey: "styleOverrides")
3434
}
3535
}
36-
36+
3737
private func savePreviouslyUsed() {
3838
if let encoded = try? JSONEncoder().encode(previouslyUsedURIs) {
3939
userDefaults.set(encoded, forKey: "previouslyUsedURIs")
4040
}
4141
}
42-
42+
4343
private func loadPreviouslyUsedURIs() {
4444
guard let data = userDefaults.data(forKey: "previouslyUsedURIs"),
4545
let decoded = try? JSONDecoder().decode([String: Date].self, from: data)
@@ -75,7 +75,7 @@ class StyleOverridesModel: ObservableObject {
7575
overrides[i].active = false
7676
}
7777
}
78-
78+
7979
previouslyUsedURIs[override.style.rawValue] = Date()
8080
previouslyUsedURIs[override.baseStyle.rawValue] = Date()
8181
}

Sources/Examples/SwiftUI Examples/LocateMeExample.swift

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ struct LocateMeExample: View {
77
@State var viewport: Viewport = .followPuck(zoom: 13, bearing: .constant(0))
88

99
var body: some View {
10-
MapReader { proxy in
10+
MapReader { _ in
1111
Map(viewport: $viewport) {
1212
Puck2D(bearing: .heading)
1313
.showsAccuracyRing(true)
@@ -21,15 +21,14 @@ struct LocateMeExample: View {
2121
}
2222
}
2323

24-
2524
/// The example demonstrates Puck and Viewport configuration that allow to follow user location.
2625
/// In this example the CoreLocationProvider is use instead of default `AppleLocationProvider`.
2726
struct LocateMeCoreLocationProviderExample: View {
2827
@State var locaionModel = LocationDataModel.createCore()
2928
@State var viewport: Viewport = .followPuck(zoom: 13, bearing: .constant(0))
3029

3130
var body: some View {
32-
MapReader { proxy in
31+
MapReader { _ in
3332
Map(viewport: $viewport) {
3433
Puck2D(bearing: .heading)
3534
.showsAccuracyRing(true)
@@ -54,7 +53,6 @@ struct LocateMeCoreLocationProviderExample: View {
5453
}
5554
}
5655

57-
5856
struct LocateMeButton: View {
5957
@Binding var viewport: Viewport
6058

Sources/Examples/SwiftUI Examples/LocationOverrideExample.swift

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,21 @@ struct LocationOverrideExample: View {
1717
@State private var provider = LocationProvider()
1818

1919
var body: some View {
20-
MapReader { proxy in
21-
Map {
22-
/// The location indicator puck position and heading is controlled by the location provider.
23-
Puck2D(bearing: .heading)
20+
Map {
21+
/// The location indicator puck position and heading is controlled by the location provider.
22+
Puck2D(bearing: .heading)
2423

25-
/// Handle tap on the map.
26-
TapInteraction { context in
27-
/// As a demonstration, override location with the last tap coordinate.
28-
let direction = provider.location.coordinate.direction(to: context.coordinate)
29-
provider.location = Location(coordinate: context.coordinate)
30-
provider.heading = Heading(direction: direction, accuracy: 0)
24+
/// Handle tap on the map.
25+
TapInteraction { context in
26+
/// As a demonstration, override location with the last tap coordinate.
27+
let direction = provider.location.coordinate.direction(to: context.coordinate)
28+
provider.location = Location(coordinate: context.coordinate)
29+
provider.heading = Heading(direction: direction, accuracy: 0)
3130

32-
return false
33-
}
31+
return false
3432
}
35-
.locationDataModel(provider.model)
3633
}
34+
.locationDataModel(provider.model)
3735
.ignoresSafeArea()
3836
.overlay(alignment: .bottom) {
3937
Text("Tap on map to move the puck")

Sources/MapboxMaps/Foundation/Extensions/Bundle+MapboxMaps.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ extension Bundle {
2525
#endif
2626
}
2727

28+
/// :nodoc:
2829
@_spi(Internal)
2930
public static var mapboxMapsMetadata: MapboxMapsMetadata = {
3031
guard let metadataPath = Bundle.mapboxMaps.url(forResource: "MapboxMaps", withExtension: "json") else {

Sources/MapboxMaps/Foundation/ForwardingDispalyLinkTarget.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import QuartzCore
1010
/// The class is designed to be used as a target for `CADisplayLink`, forwarding
1111
/// all update callbacks to the provided closure handler.
1212
internal final class ForwardingDisplayLinkTarget {
13-
13+
1414
/// The closure that will be called when the display link fires.
1515
private let handler: (CADisplayLink) -> Void
1616

Sources/MapboxMaps/Foundation/InterfaceOrientationProvider.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ internal final class DefaultInterfaceOrientationProvider {
2727
self.notificationCenter = notificationCenter
2828
self.device = device
2929
}
30-
30+
3131
convenience init() {
3232
self.init(notificationCenter: NotificationCenter.default, device: UIDevice.current)
3333
}
3434

35-
3635
private func startUpdatingInterfaceOrientation() {
3736
device.beginGeneratingDeviceOrientationNotifications()
3837
notificationCenter.addObserver(self,

Sources/MapboxMaps/Foundation/MapViewDependencyProvider.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,18 @@ import MetalKit
1717
protocol MapViewDependencyProviderProtocol: AnyObject {
1818
/// The notification center used for system event notifications.
1919
var notificationCenter: NotificationCenterProtocol { get }
20-
20+
2121
/// The bundle used for accessing app resources and configuration.
2222
var bundle: BundleProtocol { get }
23-
23+
2424
/// Creates a Metal view for rendering the map content.
2525
///
2626
/// - Parameters:
2727
/// - frame: The frame rectangle for the Metal view.
2828
/// - device: The Metal device to use for rendering, or nil to use the default device.
2929
/// - Returns: A configured Metal view ready for map rendering.
3030
func makeMetalView(frame: CGRect, device: MTLDevice?) -> MetalView
31-
31+
3232
/// Creates a display link for synchronizing rendering with the display refresh rate.
3333
///
3434
/// - Parameters:
@@ -37,7 +37,7 @@ protocol MapViewDependencyProviderProtocol: AnyObject {
3737
/// - selector: The selector to call on the target when the display link fires.
3838
/// - Returns: A display link instance, or nil if creation fails.
3939
func makeDisplayLink(window: UIWindow, target: Any, selector: Selector) -> DisplayLinkProtocol?
40-
40+
4141
/// Creates a camera animators runner for managing camera animations.
4242
///
4343
/// - Parameter mapboxMap: The map instance to animate.

Sources/MapboxMaps/Foundation/RetroactiveConformances/DisplayLinkProtocol.swift

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,26 +13,26 @@ import QuartzCore
1313
///
1414
/// - SeeAlso: `CADisplayLink` for the concrete implementation used in production.
1515
internal protocol DisplayLinkProtocol: AnyObject {
16-
16+
1717
/// The timestamp of the current frame, measured in seconds since system startup.
1818
///
1919
/// This value is typically used to calculate frame deltas for smooth animations
2020
/// and to synchronize rendering with the display refresh rate.
2121
var timestamp: CFTimeInterval { get }
22-
22+
2323
/// The duration of the previous frame, measured in seconds.
2424
///
2525
/// This value represents the time it took to render the previous frame and can be
2626
/// used for performance monitoring and adaptive frame rate adjustments.
2727
var duration: CFTimeInterval { get }
28-
28+
2929
/// The preferred number of frames per second for the display link.
3030
///
3131
/// Setting this property allows you to control the rendering frequency,
3232
/// which can help balance performance and visual quality. The actual frame rate
3333
/// may be lower than the preferred rate depending on system performance.
3434
var preferredFramesPerSecond: Int { get set }
35-
35+
3636
/// The preferred frame rate range for the display link.
3737
///
3838
/// This property provides more granular control over frame rate than
@@ -42,14 +42,14 @@ internal protocol DisplayLinkProtocol: AnyObject {
4242
/// - Note: Available on iOS 15.0 and later.
4343
@available(iOS 15.0, *)
4444
var preferredFrameRateRange: CAFrameRateRange { get set }
45-
45+
4646
/// A boolean value indicating whether the display link is currently running.
4747
///
4848
/// When `true`, the display link will fire callbacks at the specified frame rate.
4949
/// When `false`, the display link is paused and no callbacks will be fired.
5050
/// This property is essential for managing rendering lifecycle and performance.
5151
var isRunning: Bool { get set }
52-
52+
5353
/// Adds the display link to the specified run loop and mode.
5454
///
5555
/// This method starts the display link by adding it to the run loop, which will
@@ -59,7 +59,7 @@ internal protocol DisplayLinkProtocol: AnyObject {
5959
/// - runloop: The run loop to add the display link to.
6060
/// - mode: The run loop mode for the display link.
6161
func add(to runloop: RunLoop, forMode mode: RunLoop.Mode)
62-
62+
6363
/// Invalidates the display link and removes it from the run loop.
6464
///
6565
/// This method stops the display link and cleans up its resources.

0 commit comments

Comments
 (0)