Skip to content

Commit 1eb1618

Browse files
authored
Merge pull request #27 from Rallista/feat/swiftformat
2 parents 8a9320d + f1f3201 commit 1eb1618

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+559
-524
lines changed

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Release Maplibre-SwiftUI
1+
name: Release
22

33
on:
44
push:

.github/workflows/test.yml

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
name: Test maplibre-swiftui-dsl-playground
1+
name: Test
22

33
on:
44
push:
@@ -7,6 +7,19 @@ on:
77
branches: [ main ]
88

99
jobs:
10+
format-lint:
11+
runs-on: macos-14
12+
13+
steps:
14+
- name: Install tools
15+
run: brew install swiftformat
16+
17+
- name: Checkout maplibre-swiftui-dsl-playground
18+
uses: actions/checkout@v3
19+
20+
- name: Check format
21+
run: swiftformat . --lint
22+
1023
test:
1124
runs-on: macos-14
1225
strategy:
@@ -20,15 +33,15 @@ jobs:
2033
]
2134

2235
steps:
23-
- name: Install xcbeautify
36+
- name: Install tools
2437
run: brew install xcbeautify
25-
38+
2639
- uses: maxim-lobanov/setup-xcode@v1
2740
with:
2841
xcode-version: '15.0'
2942

3043
- name: Checkout maplibre-swiftui-dsl-playground
3144
uses: actions/checkout@v3
32-
45+
3346
- name: Test ${{ matrix.scheme }} on ${{ matrix.destination }}
3447
run: xcodebuild -scheme ${{ matrix.scheme }} test -skipMacroValidation -destination '${{ matrix.destination }}' | xcbeautify && exit ${PIPESTATUS[0]}

.swiftformat

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# file options
2+
3+
--exclude .build
4+
5+
# format options
6+
7+
--header ""
8+
--indent 4
9+
--importgrouping testable-bottom
10+
--maxwidth 120
11+
--swiftversion 5.9
12+
13+
# rules
14+
15+
--enable isEmpty

Package.swift

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
// swift-tools-version: 5.9
22
// The swift-tools-version declares the minimum version of Swift required to build this package.
33

4-
import PackageDescription
54
import CompilerPluginSupport
5+
import PackageDescription
66

77
let package = Package(
88
name: "MapLibreSwiftUI",
@@ -13,10 +13,12 @@ let package = Package(
1313
products: [
1414
.library(
1515
name: "MapLibreSwiftUI",
16-
targets: ["MapLibreSwiftUI"]),
16+
targets: ["MapLibreSwiftUI"]
17+
),
1718
.library(
1819
name: "MapLibreSwiftDSL",
19-
targets: ["MapLibreSwiftDSL"]),
20+
targets: ["MapLibreSwiftDSL"]
21+
),
2022
],
2123
dependencies: [
2224
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.1.0"),
@@ -32,37 +34,38 @@ let package = Package(
3234
.target(name: "InternalUtils"),
3335
.target(name: "MapLibreSwiftDSL"),
3436
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
35-
.product(name: "Mockable", package: "Mockable")
37+
.product(name: "Mockable", package: "Mockable"),
3638
],
3739
swiftSettings: [
38-
.define("MOCKING", .when(configuration: .debug))
39-
]),
40+
.define("MOCKING", .when(configuration: .debug)),
41+
]
42+
),
4043
.target(
4144
name: "MapLibreSwiftDSL",
4245
dependencies: [
4346
.target(name: "InternalUtils"),
4447
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
45-
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros")
48+
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros"),
4649
]
4750
),
4851
.target(
4952
name: "InternalUtils"
5053
),
51-
54+
5255
// MARK: Tests
53-
56+
5457
.testTarget(
5558
name: "MapLibreSwiftUITests",
5659
dependencies: [
5760
"MapLibreSwiftUI",
5861
.product(name: "MockableTest", package: "Mockable"),
59-
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
62+
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
6063
]
6164
),
6265
.testTarget(
6366
name: "MapLibreSwiftDSLTests",
6467
dependencies: [
65-
"MapLibreSwiftDSL"
68+
"MapLibreSwiftDSL",
6669
]
6770
),
6871
]

README.md

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,20 @@ Then, for each target add either the DSL (for just the DSL) or both (for the Swi
4646
Check out the (super basic) [previews at the bottom of MapView.swift](Sources/MapLibreSwiftUI/MapView.swift)
4747
or more detailed [Examples](Sources/MapLibreSwiftUI/Examples) to see how it works in practice.
4848

49+
## Developer Quick Start
50+
51+
This project uses [`swiftformat`](https://github.com/nicklockwood/SwiftFormat) to automatically handle basic swift formatting
52+
as well as to lint and ensure conformance in PRs. Check out the swiftformat [Install Guide](https://github.com/nicklockwood/SwiftFormat?tab=readme-ov-file#how-do-i-install-it)
53+
to add swiftformat to your machine.
54+
55+
Once installed, you can autoformat code using the command:
56+
57+
```sh
58+
swiftformat .
59+
```
60+
61+
Swiftformat can occasionally poorly resolve a formatting issue (e.g. when you've already line-broken a large comment). Issues like this are typically easy to manually correct.
62+
4963
## Structure
5064

5165
This package is structured into a few targets. `InternalUtils` is pretty much what it says. `MapLibreSwiftDSL` and
@@ -85,4 +99,4 @@ things like fleshing out the expresison API helpers (which will be highly repeti
8599
check out the issue tracker, as these sholud be noted there.
86100

87101
TODO: Look at PointFree's Snapshot testing that generates images of SwiftUI views. Also look at inline snapshotting.
88-
https://github.com/pointfreeco/swift-snapshot-testing
102+
https://github.com/pointfreeco/swift-snapshot-testing

Sources/InternalUtils/Utilities.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ public func addSourceIfNecessary(_ source: MLNSource, to mlnStyle: MLNStyle) ->
2525
}
2626
}
2727

28-
extension UIImage{
28+
public extension UIImage {
2929
/// Computes a SHA256 hash of the image data.
3030
///
3131
/// This is used internally to generate identifiers for images that can be used in the MapLibre GL
3232
/// style which uniquely identify `UIImage`s to the renderer.
33-
public func sha256() -> String{
33+
func sha256() -> String {
3434
if let imageData = cgImage?.dataProvider?.data as? Data {
3535
return imageData.digest.hexString
3636
}

Sources/MapLibreSwiftDSL/Enums.swift

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import MapLibre
21
import InternalUtils
2+
import MapLibre
33

44
// This file exists for convenience until / unless
55
// this is merged into the MapLibre Native Swift module OR Swift gains the
@@ -11,13 +11,12 @@ public enum LineCap {
1111
case square
1212
}
1313

14-
1514
extension LineCap: MLNRawRepresentable {
1615
public var mlnRawValue: MLNLineCap {
1716
switch self {
18-
case .butt: return .butt
19-
case .round: return .round
20-
case .square: return .square
17+
case .butt: .butt
18+
case .round: .round
19+
case .square: .square
2120
}
2221
}
2322
}
@@ -31,9 +30,9 @@ public enum LineJoin {
3130
extension LineJoin: MLNRawRepresentable {
3231
public var mlnRawValue: MLNLineJoin {
3332
switch self {
34-
case .bevel: return .bevel
35-
case .miter: return .miter
36-
case .round: return .round
33+
case .bevel: .bevel
34+
case .miter: .miter
35+
case .round: .round
3736
}
3837
}
3938
}
@@ -52,19 +51,19 @@ extension MLNVariableExpression {
5251
var nsExpression: NSExpression {
5352
switch self {
5453
case .featureAccumulated:
55-
return .featureAccumulatedVariable
54+
.featureAccumulatedVariable
5655
case .featureAttributes:
57-
return .featureAttributesVariable
56+
.featureAttributesVariable
5857
case .featureIdentifier:
59-
return .featureIdentifierVariable
58+
.featureIdentifierVariable
6059
case .geometryType:
61-
return .geometryTypeVariable
60+
.geometryTypeVariable
6261
case .heatmapDensity:
63-
return .heatmapDensityVariable
62+
.heatmapDensityVariable
6463
case .lineProgress:
65-
return .lineProgressVariable
64+
.lineProgressVariable
6665
case .zoomLevel:
67-
return .zoomLevelVariable
66+
.zoomLevelVariable
6867
}
6968
}
7069
}

Sources/MapLibreSwiftDSL/Expressions.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,16 @@
22
import Foundation
33
import MapLibre
44

5-
65
// TODO: Parameters and stops need nicer interfaces
76
// TODO: Expression should be able to accept other expressions like variable getters. Probably should be a protocol?
8-
public func interpolatingExpression(expression: MLNVariableExpression, curveType: MLNExpressionInterpolationMode, parameters: NSExpression?, stops: NSExpression) -> NSExpression {
9-
return NSExpression(forMLNInterpolating: expression.nsExpression,
10-
curveType: curveType,
11-
parameters: parameters,
12-
stops: stops)
7+
public func interpolatingExpression(
8+
expression: MLNVariableExpression,
9+
curveType: MLNExpressionInterpolationMode,
10+
parameters: NSExpression?,
11+
stops: NSExpression
12+
) -> NSExpression {
13+
NSExpression(forMLNInterpolating: expression.nsExpression,
14+
curveType: curveType,
15+
parameters: parameters,
16+
stops: stops)
1317
}

Sources/MapLibreSwiftDSL/MapLibre Extensions.swift

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
1-
// Various quality-of-life extensions to MapLibre APIs.
21

2+
// Various quality-of-life extensions to MapLibre APIs.
33
import MapLibre
44

55
// TODO: Upstream this?
6-
extension MLNPolyline {
6+
public extension MLNPolyline {
77
/// Constructs a polyline (aka LineString) from a list of coordinates.
8-
public convenience init(coordinates: [CLLocationCoordinate2D]) {
8+
convenience init(coordinates: [CLLocationCoordinate2D]) {
99
self.init(coordinates: coordinates, count: UInt(coordinates.count))
1010
}
1111
}
1212

13-
extension MLNPointFeature {
14-
public convenience init(coordinate: CLLocationCoordinate2D, configure: ((MLNPointFeature) -> Void)? = nil) {
13+
public extension MLNPointFeature {
14+
convenience init(coordinate: CLLocationCoordinate2D, configure: ((MLNPointFeature) -> Void)? = nil) {
1515
self.init()
1616
self.coordinate = coordinate
1717

Sources/MapLibreSwiftDSL/MapViewContentBuilder.swift

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,44 +3,44 @@ import Foundation
33
@resultBuilder
44
public enum MapViewContentBuilder: DefaultResultBuilder {
55
public static func buildExpression(_ expression: StyleLayerDefinition) -> [StyleLayerDefinition] {
6-
return [expression]
6+
[expression]
77
}
8-
8+
99
public static func buildExpression(_ expression: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
10-
return expression
10+
expression
1111
}
12-
13-
public static func buildExpression(_ expression: Void) -> [StyleLayerDefinition] {
14-
return []
12+
13+
public static func buildExpression(_: Void) -> [StyleLayerDefinition] {
14+
[]
1515
}
16-
16+
1717
public static func buildBlock(_ components: [StyleLayerDefinition]...) -> [StyleLayerDefinition] {
18-
return components.flatMap { $0 }
18+
components.flatMap { $0 }
1919
}
20-
20+
2121
public static func buildArray(_ components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
22-
return components
22+
components
2323
}
24-
24+
2525
public static func buildArray(_ components: [[StyleLayerDefinition]]) -> [StyleLayerDefinition] {
26-
return components.flatMap { $0 }
26+
components.flatMap { $0 }
2727
}
28-
28+
2929
public static func buildEither(first components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
30-
return components
30+
components
3131
}
32-
32+
3333
public static func buildEither(second components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
34-
return components
34+
components
3535
}
36-
36+
3737
public static func buildOptional(_ components: [StyleLayerDefinition]?) -> [StyleLayerDefinition] {
38-
return components ?? []
38+
components ?? []
3939
}
40-
40+
4141
// MARK: Custom Handler for StyleLayerCollection type.
42-
42+
4343
public static func buildExpression(_ styleCollection: StyleLayerCollection) -> [StyleLayerDefinition] {
44-
return styleCollection.layers
44+
styleCollection.layers
4545
}
4646
}

0 commit comments

Comments
 (0)