Skip to content

Commit b81853c

Browse files
Merge pull request #130 from OneBusAway/trip-nav
Trip Navigation, Linting, and Other Niceties
2 parents 53b0493 + 9b4a183 commit b81853c

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

+1074
-849
lines changed

.github/workflows/test.yaml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,21 @@ on:
1212
# https://github.com/actions/runner-images/blob/main/images/macos/macos-15-Readme.md
1313

1414
jobs:
15+
lint:
16+
runs-on: macos-15
17+
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- name: Install SwiftLint
22+
run: brew install swiftlint
23+
24+
- name: Run SwiftLint
25+
run: swiftlint --strict
26+
1527
build:
1628
runs-on: macos-15
29+
needs: lint
1730

1831
steps:
1932
- uses: actions/checkout@v4

.pre-commit-config.yaml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# See https://pre-commit.com for more information
2+
# See https://pre-commit.com/hooks.html for more hooks
3+
repos:
4+
- repo: local
5+
hooks:
6+
- id: swiftlint
7+
name: SwiftLint
8+
entry: bash -c 'swiftlint lint --strict --force-exclude --quiet'
9+
language: system
10+
pass_filenames: false
11+
always_run: true
12+
stages: [pre-push]
13+
- id: xcode-tests
14+
name: Run Xcode Tests
15+
entry: bash -c 'xcodebuild test -project OTPKitDemo.xcodeproj -scheme OTPKitDemo -destination "platform=iOS Simulator,name=iPhone 17 Pro" -quiet'
16+
language: system
17+
pass_filenames: false
18+
always_run: true
19+
stages: [pre-push]

.swiftlint.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
disabled_rules:
2+
- function_parameter_count
23
- identifier_name
4+
- line_length
5+
- multiple_closures_with_trailing_closure
36
- todo
47

58
excluded:
69
- OTPKit/.build
10+
- .build

CLAUDE.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,26 @@ swiftlint --fix
5656
brew install swiftlint
5757
```
5858

59+
#### Pre-commit Hooks
60+
The project uses [pre-commit](https://pre-commit.com) to automatically run SwiftLint and tests before pushing to GitHub.
61+
62+
```bash
63+
# Install pre-commit (first time setup)
64+
brew install pre-commit
65+
66+
# Install the git hook scripts for pre-push
67+
pre-commit install --hook-type pre-push
68+
69+
# (Optional) Run against all files manually
70+
pre-commit run --all-files
71+
```
72+
73+
Once installed, the following checks will run automatically before each push:
74+
1. **SwiftLint** - Code style and best practices validation
75+
2. **Xcode Tests** - Full test suite must pass
76+
77+
If either linting or tests fail, the push will be blocked until issues are fixed.
78+
5979
## Architecture
6080

6181
### Package Dependencies

OTPKit/.swiftlint.yml

Lines changed: 0 additions & 6 deletions
This file was deleted.

OTPKit/Sources/OTPKit/Core/Enums.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ public enum LocationMode {
1212

1313
enum Sheet: Identifiable, Hashable {
1414
case locationOptions(LocationMode)
15-
case directions
15+
case directions(Trip)
1616
case search(LocationMode)
1717
case advancedOptions
18-
case preview(Itinerary, Location?, Location?)
18+
case preview(Trip)
1919

2020
var id: Int {
2121
var hasher = Hasher()

OTPKit/Sources/OTPKit/Core/Map/MapCoordinator.swift

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,31 @@ public class MapCoordinator: ObservableObject {
176176
mapProvider.centerOnUserLocation(animated: animated)
177177
}
178178

179+
/// Focuses the map on a specific leg, showing the entire leg route
180+
/// - Parameters:
181+
/// - leg: The leg to focus on
182+
/// - bottomPadding: Additional bottom padding to account for overlays like sheets (default: 0)
183+
/// - animated: Whether to animate the movement (default: true)
184+
public func focusOnLeg(_ leg: Leg, bottomPadding: CGFloat = 0, animated: Bool = true) {
185+
let mapRect = leg.polylineMapRect
186+
187+
guard !mapRect.isNull, !mapRect.isEmpty else {
188+
Logger.main.warning("focusOnLeg: No coordinates available for leg")
189+
return
190+
}
191+
192+
// Add padding to ensure route is fully visible
193+
// Use additional bottom padding to account for sheets or other UI overlays
194+
let padding = UIEdgeInsets(
195+
top: Constants.mapPadding * 2,
196+
left: Constants.mapPadding * 2,
197+
bottom: Constants.mapPadding * 2 + bottomPadding,
198+
right: Constants.mapPadding * 2
199+
)
200+
201+
mapProvider.setVisibleMapRect(mapRect, edgePadding: padding, animated: animated)
202+
}
203+
179204
// MARK: - User Location
180205

181206
/// Shows or hides the user location on the map

OTPKit/Sources/OTPKit/Core/Miscellaneous/PresentationManager.swift

Lines changed: 0 additions & 25 deletions
This file was deleted.

OTPKit/Sources/OTPKit/Core/Models/MapExtension/MarkerItem.swift

Lines changed: 0 additions & 15 deletions
This file was deleted.

OTPKit/Sources/OTPKit/Core/Models/TripPlanner/ErrorResponse.swift renamed to OTPKit/Sources/OTPKit/Core/Models/OTP/ErrorResponse.swift

File renamed without changes.

0 commit comments

Comments
 (0)