Skip to content

Commit

Permalink
feat: swiftformat run + ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Archdoog committed Mar 2, 2024
1 parent a95c12b commit e4989ed
Show file tree
Hide file tree
Showing 49 changed files with 557 additions and 521 deletions.
28 changes: 25 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ on:
branches: [ main ]

jobs:
format-lint:
runs-on: macos-14
strategy:
matrix:
scheme: [
MapLibreSwiftUI-Package
]
destination: [
# TODO: Add more destinations
'platform=iOS Simulator,name=iPhone 15,OS=17.2'
]

steps:
- name: Install tools
run: brew install swiftformat

- name: Checkout maplibre-swiftui-dsl-playground
uses: actions/checkout@v3

- name: Check format
run: swiftformat . --lint

test:
runs-on: macos-14
strategy:
Expand All @@ -20,15 +42,15 @@ jobs:
]

steps:
- name: Install xcbeautify
- name: Install tools
run: brew install xcbeautify

- uses: maxim-lobanov/setup-xcode@v1
with:
xcode-version: '15.0'

- name: Checkout maplibre-swiftui-dsl-playground
uses: actions/checkout@v3

- name: Test ${{ matrix.scheme }} on ${{ matrix.destination }}
run: xcodebuild -scheme ${{ matrix.scheme }} test -skipMacroValidation -destination '${{ matrix.destination }}' | xcbeautify && exit ${PIPESTATUS[0]}
15 changes: 15 additions & 0 deletions .swiftformat
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# file options

--exclude .build

# format options

--header ""
--indent 4
--importgrouping testable-bottom
--maxwidth 120
--swiftversion 5.9

# rules

--enable isEmpty
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
"kind" : "remoteSourceControl",
"location" : "https://github.com/maplibre/maplibre-gl-native-distribution.git",
"state" : {
"revision" : "3df876f8f2c6c591b0f66a29b3e216020afc885c",
"version" : "6.0.0"
"revision" : "818e1d6b83e4cbe8482eca3e6e57d3f560926157",
"version" : "6.1.1"
}
},
{
Expand Down
25 changes: 14 additions & 11 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// swift-tools-version: 5.9
// The swift-tools-version declares the minimum version of Swift required to build this package.

import PackageDescription
import CompilerPluginSupport
import PackageDescription

let package = Package(
name: "MapLibreSwiftUI",
Expand All @@ -13,10 +13,12 @@ let package = Package(
products: [
.library(
name: "MapLibreSwiftUI",
targets: ["MapLibreSwiftUI"]),
targets: ["MapLibreSwiftUI"]
),
.library(
name: "MapLibreSwiftDSL",
targets: ["MapLibreSwiftDSL"]),
targets: ["MapLibreSwiftDSL"]
),
],
dependencies: [
.package(url: "https://github.com/maplibre/maplibre-gl-native-distribution.git", from: "6.1.0"),
Expand All @@ -32,37 +34,38 @@ let package = Package(
.target(name: "InternalUtils"),
.target(name: "MapLibreSwiftDSL"),
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
.product(name: "Mockable", package: "Mockable")
.product(name: "Mockable", package: "Mockable"),
],
swiftSettings: [
.define("MOCKING", .when(configuration: .debug))
]),
.define("MOCKING", .when(configuration: .debug)),
]
),
.target(
name: "MapLibreSwiftDSL",
dependencies: [
.target(name: "InternalUtils"),
.product(name: "MapLibre", package: "maplibre-gl-native-distribution"),
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros")
.product(name: "MapLibreSwiftMacros", package: "maplibre-swift-macros"),
]
),
.target(
name: "InternalUtils"
),

// MARK: Tests

.testTarget(
name: "MapLibreSwiftUITests",
dependencies: [
"MapLibreSwiftUI",
.product(name: "MockableTest", package: "Mockable"),
.product(name: "SnapshotTesting", package: "swift-snapshot-testing")
.product(name: "SnapshotTesting", package: "swift-snapshot-testing"),
]
),
.testTarget(
name: "MapLibreSwiftDSLTests",
dependencies: [
"MapLibreSwiftDSL"
"MapLibreSwiftDSL",
]
),
]
Expand Down
4 changes: 2 additions & 2 deletions Sources/InternalUtils/Utilities.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ public func addSourceIfNecessary(_ source: MLNSource, to mlnStyle: MLNStyle) ->
}
}

extension UIImage{
public extension UIImage {
/// Computes a SHA256 hash of the image data.
///
/// This is used internally to generate identifiers for images that can be used in the MapLibre GL
/// style which uniquely identify `UIImage`s to the renderer.
public func sha256() -> String{
func sha256() -> String {
if let imageData = cgImage?.dataProvider?.data as? Data {
return imageData.digest.hexString
}
Expand Down
29 changes: 14 additions & 15 deletions Sources/MapLibreSwiftDSL/Enums.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import MapLibre
import InternalUtils
import MapLibre

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


extension LineCap: MLNRawRepresentable {
public var mlnRawValue: MLNLineCap {
switch self {
case .butt: return .butt
case .round: return .round
case .square: return .square
case .butt: .butt
case .round: .round
case .square: .square
}
}
}
Expand All @@ -31,9 +30,9 @@ public enum LineJoin {
extension LineJoin: MLNRawRepresentable {
public var mlnRawValue: MLNLineJoin {
switch self {
case .bevel: return .bevel
case .miter: return .miter
case .round: return .round
case .bevel: .bevel
case .miter: .miter
case .round: .round
}
}
}
Expand All @@ -52,19 +51,19 @@ extension MLNVariableExpression {
var nsExpression: NSExpression {
switch self {
case .featureAccumulated:
return .featureAccumulatedVariable
.featureAccumulatedVariable
case .featureAttributes:
return .featureAttributesVariable
.featureAttributesVariable
case .featureIdentifier:
return .featureIdentifierVariable
.featureIdentifierVariable
case .geometryType:
return .geometryTypeVariable
.geometryTypeVariable
case .heatmapDensity:
return .heatmapDensityVariable
.heatmapDensityVariable
case .lineProgress:
return .lineProgressVariable
.lineProgressVariable
case .zoomLevel:
return .zoomLevelVariable
.zoomLevelVariable
}
}
}
16 changes: 10 additions & 6 deletions Sources/MapLibreSwiftDSL/Expressions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,16 @@
import Foundation
import MapLibre


// TODO: Parameters and stops need nicer interfaces
// TODO: Expression should be able to accept other expressions like variable getters. Probably should be a protocol?
public func interpolatingExpression(expression: MLNVariableExpression, curveType: MLNExpressionInterpolationMode, parameters: NSExpression?, stops: NSExpression) -> NSExpression {
return NSExpression(forMLNInterpolating: expression.nsExpression,
curveType: curveType,
parameters: parameters,
stops: stops)
public func interpolatingExpression(
expression: MLNVariableExpression,
curveType: MLNExpressionInterpolationMode,
parameters: NSExpression?,
stops: NSExpression
) -> NSExpression {
NSExpression(forMLNInterpolating: expression.nsExpression,
curveType: curveType,
parameters: parameters,
stops: stops)
}
10 changes: 5 additions & 5 deletions Sources/MapLibreSwiftDSL/MapLibre Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Various quality-of-life extensions to MapLibre APIs.

// Various quality-of-life extensions to MapLibre APIs.
import MapLibre

// TODO: Upstream this?
extension MLNPolyline {
public extension MLNPolyline {
/// Constructs a polyline (aka LineString) from a list of coordinates.
public convenience init(coordinates: [CLLocationCoordinate2D]) {
convenience init(coordinates: [CLLocationCoordinate2D]) {
self.init(coordinates: coordinates, count: UInt(coordinates.count))
}
}

extension MLNPointFeature {
public convenience init(coordinate: CLLocationCoordinate2D, configure: ((MLNPointFeature) -> Void)? = nil) {
public extension MLNPointFeature {
convenience init(coordinate: CLLocationCoordinate2D, configure: ((MLNPointFeature) -> Void)? = nil) {
self.init()
self.coordinate = coordinate

Expand Down
42 changes: 21 additions & 21 deletions Sources/MapLibreSwiftDSL/MapViewContentBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -3,44 +3,44 @@ import Foundation
@resultBuilder
public enum MapViewContentBuilder: DefaultResultBuilder {
public static func buildExpression(_ expression: StyleLayerDefinition) -> [StyleLayerDefinition] {
return [expression]
[expression]
}

public static func buildExpression(_ expression: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return expression
expression
}
public static func buildExpression(_ expression: Void) -> [StyleLayerDefinition] {
return []

public static func buildExpression(_: Void) -> [StyleLayerDefinition] {
[]
}

public static func buildBlock(_ components: [StyleLayerDefinition]...) -> [StyleLayerDefinition] {
return components.flatMap { $0 }
components.flatMap { $0 }
}

public static func buildArray(_ components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return components
components
}

public static func buildArray(_ components: [[StyleLayerDefinition]]) -> [StyleLayerDefinition] {
return components.flatMap { $0 }
components.flatMap { $0 }
}

public static func buildEither(first components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return components
components
}

public static func buildEither(second components: [StyleLayerDefinition]) -> [StyleLayerDefinition] {
return components
components
}

public static func buildOptional(_ components: [StyleLayerDefinition]?) -> [StyleLayerDefinition] {
return components ?? []
components ?? []
}

// MARK: Custom Handler for StyleLayerCollection type.

public static func buildExpression(_ styleCollection: StyleLayerCollection) -> [StyleLayerDefinition] {
return styleCollection.layers
styleCollection.layers
}
}
Loading

0 comments on commit e4989ed

Please sign in to comment.