Typos works differently from other spell checkers, and is easier to keep updated
I’ve been struggling with lots of typos on my articles. I tried a few solutions, and eventually found one that works for me called typos.
Running typos
on this very blog shows that I have an embarrassing amount of typos. Anyway, check out how it’s been helpful here:
ArticleSubcribeBox
is checked as “Article Subcribe Box”).› brew install typos-cli··
› typos
error: `classses` should be `classes` --> ./articles/2023/advanced-tailwind.mdx:185:18 |185 | ### Other pseudo-classses | ^^^^^^^^ |error: `Subcribe` should be `Subscribe` --> ./articles/2022/public-cdns-arent-useful-anymore.mdx:64:12 |64 | <ArticleSubcribeBox /> | ^^^^^^^^ |
Unlike traditional spell checkers, typos
doesn’t use dictionaries of valid words. Instead, it maintains a list of typo corrections.
Typos maintains a large typo correction list (shown below). As of Dec 2023, it has 4291 entries, and is updated regularly.
abudance->abundancedidnt->didn'trealyl->reallysurviver->survivoryaer->year···
You can argue Typos’s approach makes it less effective, but I’ve found that it makes it more practical.
My experience with dictionary-based spell checkers like cspell needed a lot of configuration to deal with false positives.
This is less of a problem with typos
.
One of the use cases I wanted this for is to add spell check to rstacruz/
I’d prefer to lower the barrier to contribution as much as possible. Typos seems like a good fit for this.
The typos GitHub Action finishes in 8 seconds in one moderately-sized repo I maintain. My experience with a code editor is seamless too… corrections happen as instantly as I typed.
brew install typos-clicargo install typos-clisudo pacman -S typos
typos
to show changestypos -w
to apply changes to all filesAlso: Typos comes with a --diff
option (and --format brief
, shown below) to inspect changes. Running typos -w
to apply the changes.
# Inspect changes› typos --format briefarticles/2022/public-cdns….md:64:12: `Reuseable` -> `Reusable`articles/2022/articl….md:14:8: `mutiple` -> `multiple`articles/2022/lua….md:14:8: `DotA` -> `data`
# Write to file› typos -w
.typos.toml
files.extend-exclude
)default.extend-words
)While false positives are rare, they do happen. The word DotA
above is one of such examples. Typos has a configuration file to deal with these.
[default.extend-words]"DotA" = "DotA" # don't autocorrect 'DotA' to 'data'
[files]extend-exclude = [ # Ignore these files "localized/*.po",]
Unfortunately, I couldn’t find integrations to other editors. In any case, it’s also implemented as an LSP, which means it should be possible to integrate it with other LSP-supporting editors.
Before settling on Typos, I also had a look at codespell and cspell.
codespell is another spell checker with very similar goals to Typos. It also uses a list of typo corrections. In my experience, it works very well. I ended up sticking to Typos for 2 reasons:
cspell is a dictionary-based spell checker. I’ve given this a try in some code bases I maintained, and usually produced good results.
Ultimately, I ended up not using it. While cspell can be very comprehensive if you took time to add the right dictionaries, my needs were a bit more modest and I preferred the low maintenance approach of Typos.
Typos is a spell checker that works on code and prose. It’s low maintenance, and works with my favourite editors. While I might consider cspell for when spell checking must be as strict as possible, I think Typos is a great fit for cases where convenience is more important.
Do you use a spell checker in your editor? Let me know your experiences in the comments below.
I am a web developer helping make the world a better place through JavaScript, Ruby, and UI design. I write articles like these often. If you'd like to stay in touch, subscribe to my list.