By this point, we all know and love Xcode’s check spelling while typing feature.
However, that feature is missing something critical in my opinion: the ability to list in one place, all the typos in the codebase.
SwiftTypoDetector
I created a tool that is easy to install, and easy to use, to achieve that functionality.
Installation
The installation is really simple, you just have to:
- Clone the repository
- Run the
./setup.sh
script
Usage
Just run: ./find_typos.rb path/to/your-project
That’s it, the ruby script will iterate over all the files, and print to the console all the typos.
Aside from checking against the US dictionary, the script will also check against these swift-generic-words.
Learning words
Each of our projects contain several words that are not included in the US dictionary. My name, for example, is not in there.
You can add custom words to one or multiple learned_words.txt files to make the tool aware of them.
The script will find all the files named learned_words.txt
in your project, and learn all the words.
Demo
Tip: You can Command + Click
on the files in the console to open them with Xcode.
Console alias
You could create a custom method and add it to your .zshrc
:
1.
- vim ~/.zshrc
2.
typos() {
original_dir=$(pwd)
cd ~/path/to-the-tool/SwiftTypoDetector
./find_typos.rb "${original_dir}/$1"
cd - > /dev/null # Go back to the original directory
}
3.
- source ~/.zshrc
4.
- cd your/project/path && typos
Next Steps
I think a natural next step for the tool would be to make it a Ruby Gem, so people can start using it via bundler.
Also, it should be pretty easy to provide support for other extensions.