Formatting and Linting
To maintain a consistent code style across the Untold Engine repo, we use SwiftFormat. SwiftFormat is a code formatter for Swift that helps enforce Swift style conventions and keep the codebase clean. If you don't have SwiftFormat installed, see the Installing SwiftFormat section below.
Quick Formatting & Linting
Navigate to the root directory of Untold Engine and then run the commands below:
🔍 Lint files
To lint (check) all Swift files without making changes:
swiftformat --lint . --swiftversion 5.8 --reporter github-actions-log
Or, using the Makefile:
make lint
This command runs the same lint configuration as our GitHub Actions workflow and pre-commit hook, ensuring consistent results locally and in CI.
✅ Formatting Files
To format files:
swiftformat --swiftversion 5.8 .
Alternatively, you can use the Makefile shortcut:
make format
💡 Tip If the pre-commit hook blocks your commit due to formatting issues, simply run:
make format
then re-stage your changes and try committing again.
You can bypass the hook temporarily (not recommended) with:
git commit --no-verify
Installing SwiftFormat
The simplest way to install SwiftFormat is through the command line.
- Install SwiftFormat Using Homebrew: Open the terminal and run the following command:
brew install swiftformat
- Verify Installation: After installation, verify that SwiftFormat is installed correctly by running:
swiftformat --version
This should print the installed version of SwiftFormat.
Using SwiftFormat
Format a Single File
To format a specific Swift file:
-
Open the terminal and navigate to your project directory.
-
Run the following command:
swiftformat path/to/YourFile.swift
This will format YourFile.swift according to the default rules.
Format Multiple Files
To format all Swift files in your project:
-
Navigate to your project directory in the terminal.
-
Run the following command:
swiftformat .
This will recursively format all Swift files in the current directory and its subdirectories.