Ensure consistent member ordering in Swift types to improve readability and maintainability.
swift-marshal is an AST-based CLI that ensures consistent member ordering within Swift type declarations. It reports violations with check and applies fixes with fix, driven by SwiftSyntax and a declarative configuration file.
Inconsistent member ordering increases:
- cognitive load when navigating code
- friction during code reviews
- inconsistency across teams and codebases
swift-marshal helps maintain a predictable structure, making code easier to read, review, and maintain.
- Ensures consistent member ordering using AST-based analysis
- Preserves original logic and formatting
- Supports automated fixes via CLI
- Can be integrated into CI pipelines
- Configurable through a declarative YAML file
brew tap ericodx/homebrew-tools
brew install swift-marshalOther installation methods — pre-built binary, build from source, pre-commit hook, Xcode plugin — are covered in the Installation Guide.
# Generate a config file (auto-detects your source directories)
swift-marshal init
# Check for violations
swift-marshal check
# Apply fixes
swift-marshal fixExample output:
Sources/App/Models/User.swift:
struct User (line 3)
[needs reordering]
original:
- instance_method fullName
- instance_property firstName
- initializer init
reordered:
- initializer init
- instance_property firstName
- instance_method fullName
✗ 1 type in 1 file needs reordering
Run 'swift-marshal fix' to apply changes
Drop a .swift-marshal.yaml in the project root to control member order, paths, and extension handling:
version: 1
ordering:
members:
- typealias
- associatedtype
- initializer
- type_property
- instance_property
- subtype
- type_method
- instance_method
- subscript
- deinitializer
extensions:
strategy: separate
respect_boundaries: true
paths:
- Sources/Full reference in the Usage & Configuration Guide.
| Document | Description |
|---|---|
| Installation | Homebrew, binary, source, pre-commit hook, Xcode plugin |
| Usage & Configuration | CLI options, YAML config, output formats, CI integration |
| Architecture | Module map, pipeline design, configuration model, AST rewriting |
| Codebase Reference | Every type, protocol, and stage documented |