Skip to content

Commit b99e434

Browse files
committed
update tooling
- add pre-commit - add pre-commit-config - update Makefile
1 parent 43b7121 commit b99e434

File tree

4 files changed

+130
-49
lines changed

4 files changed

+130
-49
lines changed

.pre-commit-config.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
# Pre-commit configuration for Critical Maps iOS
2+
# See https://pre-commit.com for more information
3+
4+
repos:
5+
- repo: local
6+
hooks:
7+
- id: swiftformat
8+
name: SwiftFormat
9+
entry: swiftformat
10+
language: system
11+
files: \.swift$
12+
args: [--config, .swiftformat]
13+
description: "Format Swift code with SwiftFormat"
14+
minimum_pre_commit_version: "3.0.0"
15+
16+
- id: swiftlint-fix
17+
name: SwiftLint Auto-fix
18+
entry: swiftlint
19+
language: system
20+
files: \.swift$
21+
args: [--fix, --quiet]
22+
description: "Auto-fix SwiftLint violations"
23+
minimum_pre_commit_version: "3.0.0"
24+
25+
- id: swiftlint
26+
name: SwiftLint
27+
entry: swiftlint
28+
language: system
29+
files: \.swift$
30+
args: [--quiet]
31+
description: "Lint Swift code with SwiftLint"
32+
minimum_pre_commit_version: "3.0.0"
33+
34+
# Commented out - only running Swift tools for now
35+
# - repo: https://github.com/pre-commit/pre-commit-hooks
36+
# rev: v4.4.0
37+
# hooks:
38+
# - id: trailing-whitespace
39+
# exclude: \.(md|swift)$
40+
# - id: end-of-file-fixer
41+
# exclude: \.(png|jpg|jpeg|gif|svg|ico|swift)$
42+
# - id: check-yaml
43+
# files: \.ya?ml$
44+
# - id: check-json
45+
# files: \.json$
46+
# - id: check-merge-conflict
47+
# - id: check-added-large-files
48+
# args: [--maxkb=1000]

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ In general, we follow the "fork-and-pull" Git workflow.
88
4. **Push** your work back up to your fork
99
5. Submit a **Pull request** so that we can review your changes
1010

11-
NOTES:
12-
- Be sure to merge the latest from "upstream" before making a pull request!
13-
- Please use the simulator specified in Fastfile ("snapshot_test" lane) to run snapshot tests
11+
> [!NOTE]
12+
> - Be sure to merge the latest from "upstream" before making a pull request!
13+
> - Please use the simulator specified in Fastfile ("snapshot_test" lane) to run snapshot tests

Makefile

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: help default tests assets dependencies ruby lint format clean setup
1+
.PHONY: help default tests assets dependencies ruby lint format clean setup install-pre-commit pre-commit-run pre-commit-update check-versions
22

33
default: tests
44

@@ -7,10 +7,36 @@ help: ## Show this help
77
@echo ""
88
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf " \033[36m%-15s\033[0m %s\n", $$1, $$2}'
99

10-
setup: dependencies ## Complete project setup for new developers
11-
@echo "🎉 Project setup complete! You can now run 'make tests' or open CriticalMaps.xcodeproj"
10+
check-versions: ## Check tool versions against .tool-versions
11+
@echo "🔍 Checking tool versions..."
12+
@echo "Expected versions (from .tool-versions):"
13+
@grep -v '^#' .tool-versions | while read tool version; do \
14+
echo " $$tool: $$version"; \
15+
done
16+
@echo ""
17+
@echo "Installed versions:"
18+
@if command -v swiftformat >/dev/null 2>&1; then \
19+
echo " swiftformat: $$(swiftformat --version)"; \
20+
else \
21+
echo " swiftformat: ❌ not installed"; \
22+
fi
23+
@if command -v swiftlint >/dev/null 2>&1; then \
24+
echo " swiftlint: $$(swiftlint version)"; \
25+
else \
26+
echo " swiftlint: ❌ not installed"; \
27+
fi
28+
@if command -v swiftgen >/dev/null 2>&1; then \
29+
echo " swiftgen: $$(swiftgen --version | grep -o 'v[0-9\.]*' | head -1 | sed 's/v//')"; \
30+
else \
31+
echo " swiftgen: ❌ not installed"; \
32+
fi
33+
@if command -v pre-commit >/dev/null 2>&1; then \
34+
echo " pre-commit: $$(pre-commit --version | grep -o '[0-9\.]*')"; \
35+
else \
36+
echo " pre-commit: ❌ not installed"; \
37+
fi
1238

13-
dependencies: ruby ## Install all development dependencies
39+
dependencies: ruby check-versions ## Install all development dependencies
1440
@echo "📦 Installing development tools..."
1541
@if ! command -v swiftformat >/dev/null 2>&1; then \
1642
echo "Installing swiftformat..."; \
@@ -30,6 +56,12 @@ dependencies: ruby ## Install all development dependencies
3056
else \
3157
echo "✅ swiftlint already installed"; \
3258
fi
59+
@if ! command -v pre-commit >/dev/null 2>&1; then \
60+
echo "Installing pre-commit..."; \
61+
brew install pre-commit; \
62+
else \
63+
echo "✅ pre-commit already installed"; \
64+
fi
3365

3466
ruby: ## Install Ruby dependencies (bundler, fastlane)
3567
@echo "💎 Setting up Ruby environment..."
@@ -68,10 +100,15 @@ tests: ## Run all tests via Fastlane
68100
@echo "🧪 Running tests..."
69101
@bundle exec fastlane ios test
70102

71-
clean: ## Clean build artifacts and derived data
72-
@echo "🗑️ Cleaning build artifacts..."
73-
@rm -rf build/
74-
@rm -rf .build/
75-
@rm -rf CriticalMapsKit/.build/
76-
@xcodebuild -project CriticalMaps.xcodeproj -alltargets clean 2>/dev/null || true
77-
@echo "✅ Clean complete"
103+
install-pre-commit: ## Install pre-commit hooks
104+
@echo "🪝 Installing pre-commit hooks..."
105+
@pre-commit install
106+
@echo "✅ Pre-commit hooks installed"
107+
108+
pre-commit-run: ## Run pre-commit on all files
109+
@echo "🔍 Running pre-commit on all files..."
110+
@pre-commit run --all-files
111+
112+
pre-commit-update: ## Update pre-commit hook versions
113+
@echo "⬆️ Updating pre-commit hooks..."
114+
@pre-commit autoupdate

README.md

Lines changed: 31 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ http://en.wikipedia.org/wiki/Critical_Mass_(cycling)
1717

1818
## What's this app?
1919

20-
This iOS app is made for Critical Maps. It tracks your location and shares it with all other participants of the Critical Mass bicycle protest. You can use the chat to communicate with all other participants.
20+
This iOS app is made for Critical Maps. It tracks your location and shares it with all other participants of the Critical Mass bicycle protest.
2121

2222
## How the App Works
2323

@@ -27,20 +27,9 @@ Critical Maps connects cyclists during Critical Mass rides through real-time loc
2727
- **🗺️ Real-time Location Tracking**: Your location is shared anonymously with other riders on an interactive map
2828
- **💬 Live Chat System**: Communicate with all participants in real-time during rides
2929
- **📅 Next Ride Events**: Discover upcoming Critical Mass events in your area
30+
- **🌐 Social Integration**: Stay connected through an integrated Mastodon feed
31+
- **🔒 Privacy-Focused**: Anonymous participation with observationmode. Additional protection through privacy zones.
3032
- **🎨 Customizable Experience**: Personalize your rider appearance and app settings
31-
- **🌐 Social Integration**: Stay connected through integrated Mastodon feeds
32-
- **🔒 Privacy-Focused**: Anonymous participation with optional customization
33-
34-
### Technical Architecture
35-
Built with modern iOS development practices:
36-
- **SwiftUI** for declarative, responsive user interfaces
37-
- **The Composable Architecture (TCA)** for predictable state management and unidirectional data flow
38-
- **Swift Package Manager** for dependency management
39-
- **Real-time API Integration** for live location sharing and chat
40-
41-
## Where can I get the app?
42-
43-
- [AppStore](https://apps.apple.com/de/app/critical-maps/id918669647)
4433

4534
## Project Setup
4635

@@ -96,28 +85,13 @@ This repo contains both the client for running the entire [Critical Maps](https:
9685
2. **Open the Xcode project**: `CriticalMaps.xcodeproj`
9786
3. **Run the app**: Select the `Critical Maps` target in Xcode and run (`⌘R`)
9887

99-
#### Development Setup (Optional)
100-
Install all development tools with:
101-
```sh
102-
make setup
103-
```
10488

105-
Or install components individually:
89+
Install dependencies individually:
10690
```sh
107-
make dependencies # Install Swift tools (SwiftLint, SwiftFormat, SwiftGen) + Ruby gems
108-
make ruby # Install only Ruby dependencies (bundler, fastlane)
91+
make bootstrap # Install Swift tools (SwiftLint, SwiftFormat, SwiftGen)
92+
make ruby # Install Ruby dependencies (bundler, fastlane)
10993
```
11094

111-
**Available Makefile Commands:**
112-
- `make help` - Show all available commands
113-
- `make setup` - Complete project setup for new developers
114-
- `make tests` - Run all tests
115-
- `make lint` - Run SwiftLint with auto-fix
116-
- `make format` - Format code with SwiftFormat
117-
- `make assets` - Generate type-safe assets
118-
- `make clean` - Clean build artifacts
119-
120-
12195
### Assets & Code Generation
12296

12397
#### SwiftGen Integration
@@ -160,7 +134,7 @@ xcodebuild test -scheme MapFeatureTests -destination 'platform=iOS Simulator,nam
160134

161135
## Contribute
162136

163-
- Please report bugs with GitHub [issues](https://github.com/CriticalMaps/criticalmaps-ios/issues).
137+
- Please report bugs or feature requests with GitHub [issues](https://github.com/CriticalMaps/criticalmaps-ios/issues).
164138
- If you can code please check the build & contribute guide below.
165139
- If you have some coins left you can help to finance the project on [Open Collective](https://opencollective.com/criticalmaps).
166140

@@ -175,15 +149,37 @@ In general, we follow the "fork-and-pull" Git workflow.
175149
5. Submit a **Pull request** so that we can review your changes
176150

177151
#### Development Guidelines
178-
- Follow the existing code style and SwiftLint rules
152+
- Follow the existing code style and SwiftLint rules but not a hard rule
179153
- Write tests for new features and bug fixes
180-
- Update documentation and comments when adding new functionality
181154
- Run `make assets` after adding new images or localization strings
182155
- Ensure all CI checks pass before requesting review
183156

157+
#### Pre-commit Hooks
158+
The project uses pre-commit hooks to automatically format and lint code before commits:
159+
160+
**Manual Setup:**
161+
```sh
162+
make install-pre-commit # Install hooks only
163+
```
164+
165+
**What runs on each commit:**
166+
- **SwiftFormat** - Automatically formats Swift code
167+
- **SwiftLint Auto-fix** - Fixes violations that can be corrected automatically
168+
- **SwiftLint** - Reports remaining violations (warnings only, won't block commits)
169+
170+
> [!NOTE]
171+
> Pre-commit hooks currently only process Swift files. Other file types (YAML, JSON, etc.) are not automatically processed.
172+
173+
**Manual pre-commit run:**
174+
```sh
175+
make pre-commit-run # Run on all files
176+
pre-commit run --files changed_file.swift # Run on specific files
177+
```
178+
184179
**Notes**:
185180
- Be sure to merge the latest from "upstream" before making a pull request!
186181
- For significant changes, consider opening an issue first to discuss the approach
182+
- Pre-commit hooks ensure code consistency across all contributors
187183

188184
## Open Source & Copying
189185

0 commit comments

Comments
 (0)