A tool for checking spelling in Swift code
To install SwiftySpell using CocoaPods, add the following line to your Podfile
, then run pod install
:
pod 'SwiftySpell'
To install SwiftySpell manually, you can run the following commands:
cd ~/Downloads
LATEST_RELEASE=$(curl -s https://api.github.com/repos/YassineLafryhi/SwiftySpell/releases/latest | grep tag_name | cut -d '"' -f 4)
wget "https://github.com/YassineLafryhi/SwiftySpell/releases/download/${LATEST_RELEASE}/SwiftySpell-v${LATEST_RELEASE}.zip"
unzip "SwiftySpell-v${LATEST_RELEASE}.zip"
sudo mkdir -p /usr/local/bin
sudo mv swiftyspell /usr/local/bin/swiftyspell
sudo chmod +x /usr/local/bin/swiftyspell
Note
SwiftySpell
supports the same languages as the NSSpellChecker
class from AppKit. To see the list of supported languages, run the following command: swiftyspell languages
.
Configure SwiftySpell by running swiftyspell init
command inside the project folder, then edit the generated .swiftyspell.yml
configuration file.
This is an example of the configuration file:
# Languages to check
languages:
- en
# Words to ignore
ignoreList:
- iOS
# Regular expressions to exclude
excludePatterns:
- \b[0-9a-fA-F]{6}\b # Color hex codes
- \bhttps?:\/\/[^\s]+\b # URLs
# Files to exclude
excludeFiles:
- Constants.swift
# Directories to exclude
excludeDirectories:
- Pods # Exclude the Pods directory for a CocoaPods project
Integrate SwiftySpell into your Xcode project to get warnings displayed in the issue navigator.
To do so, select the project in the file navigator, then select the primary app target, and go to Build Phases. Click the + and select "New Run Script Phase". Insert the following script:
If installed using CocoaPods :
"${PODS_ROOT}/SwiftySpell/SwiftySpell" check "${SRCROOT}"
If installed manually :
if which swiftyspell >/dev/null; then
swiftyspell check "${SRCROOT}"
else
echo "warning: SwiftySpell is not installed, download it from: https://github.com/YassineLafryhi/SwiftySpell"
fi
Some examples of the warnings displayed in Xcode:
Run SwiftySpell from the command line by navigating to the directory containing the Swift project you want to check and running the following command:
swiftyspell check .
You can use SwiftySpell as a pre-commit git hook to check spelling before committing your changes. To do so, add the following to the .git/hooks/pre-commit
file:
#!/bin/sh
if [ -n "$(swiftyspell check .)" ]; then
echo "Spelling errors found. Please fix them before committing."
exit 1
fi
To build SwiftySpell from source, run the following commands:
git clone https://github.com/YassineLafryhi/SwiftySpell.git
cd SwiftySpell
xcodebuild -project SwiftySpell.xcodeproj -scheme SwiftySpell -configuration Release build CONFIGURATION_BUILD_DIR=$(pwd)/Build
open Build
# Then you can move Build/SwiftySpell to /usr/local/bin/swiftyspell
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request