Spell Checking Your Programming From The Linux Command Line

For most of us who didn’t do well in high school English class, spell checkers are a real game-changer. Sure, you can still swap a “to” and a “too,” but a spell checker will catch a lot of typos. But what about in your source code? You usually don’t spell check source code and even if you did, the rules are funny. After all, “my_proejct” is a perfectly fine variable name, but you probably meant “my_project.” That’s where a program called typos comes in. It aims to be a spell checker for source code that is fast enough and with a low enough false positive rate that you can run it against changed code and reject spelling problems.

Sure, if “my_proejct” is a one-time typo, the compiler or interpreter will probably catch it. But it won’t catch comments and it also won’t catch something you spell wrong consistently. For that you need something like typos.

You can include a custom dictionary and also per-language dictionaries. It is aware of camel case and snake case and knows to ignore hex codes. The only thing we saw it doesn’t handle well is C-language escapes.

There are apparently other checkers out there and we learned about them from this project’s comparison grid. There’s misspell, codespell, and scspell. This is the tool we didn’t know we needed, but probably do.

If you are writing bash scripts and want to check their correctness there is shellcheck, which sounds like spell check but has a whole different function. If you want to brush up on your spelling, you can always hack a Speak ‘n Spell.

17 thoughts on “Spell Checking Your Programming From The Linux Command Line

    1. Godwin’s Law?

      But also, no. Code is written for two audiences: a computer, and whoever has to maintain it in the future. Computers are even more susceptible to typos and syntax errors than a regular human-type person is; errors in the code have to be fixed program won’t run, or will run with difficult-to-locate errors.

      And the second audience, the maintainers, need comments and instructions as free of misspellings and grammar errors as possible so they can focus on what they’re maintaining, not lose time trying to decipher a poorly worded comment or hunt for a misspelled variable.

  1. Seconded (thirded?) for vim spellcheck.

    Also, many languages have told available to check style and syntax. Python enforces a lot of style things out of the box, while Perl has the Perl:: Tidy module to identify and fix style issues.

    It’s neat that there are tools to perform some of those tasks across multiple languages – thanks for the article!

    1. Right! I am reading this going thinking the same thing. ” Misspelled variable ” Uh… if you misspell it either defining it or using it later it wont compile people, so I se no point there. Also, if i mispell something a word or two in the comments and you as a coder cannot figure out a few letters out of place than you dont deserve to be coding in the first place.

    2. Not everyone uses an IDE, some out of principle, some out of necessity.

      A lot of us just like command line tools better anyway, because scripting is so easy with them.

      Just because *you* haven’t found a use for a tool doesn’t make it useless.

      1. This.

        I admit that I’m tired of all the naysayers acting like they are the center of the universe and the *only* way to do something is their way. Point and drool coders think everyone needs a mouse and an advanced IDE. The war between vim and emacs is legendary. Terminal and editor keyboarders think IDE coders are slow and ignorant. All zealots pretending theirs is the only way are irritating and should learn to just shut up.

        You have a different way? Congrats. Share your way but don’t pretend that yours is the only real solution.

  2. Spellcheckers are so hard to write, the ones for word processors have turned into a black box nobody wants to touch.

    In series of articles called “Rebuilding the Spellchecker”, Zverok wanted to rebuild and maybe extend the internals of Hunspell. At the end of it, he says he knows less than he started! It’s NOT a matter of just “build a dictionary, then lookup”. , Thanks to human language, context is killer and unsolvable. The challenge is almost a big as street mapping.

    “I forgot how to spellcheck”
    https://zverok.github.io/blog/2021-05-06-how-to-spellcheck.html

    1. So funny thing, is that the “best” spell checker is actually more or less constantly changing, it’s just on a longer time scale. Maybe 15-20yrs ago is when hunspell started overtaking aspell. I think the new one I heard about maybe a year and a half ago is MySpell? It’s definitely an intense field though, and probably not amenable to many newbies. Word processor nerds learn a lot of unique stuff. From a former word processor nerd…

      (Looks like an interesting blog series, thanks for the link!)

  3. I encounter a huge number of really simple typos in the log files of enterprise software that they don’t expect customers to see, it always makes me worry about the quality of the rest of their code.

  4. There’s a difference between typos (I have a lot of those with the tablet) and not knowing how to spell a word.

    I’ve dabbled with spellcheckers, but they always seemed like too much work.

    Dictionaries are handy, but so are paperback books that just list words tocheck spelling.

    Linux has the “look” utility that has other uses, but also can be used to find words. So long as you know some of the word, matches pop up. And it’s the command line. Igather you can add words, or whole lists of words.

    This is Unix, really simple utilities that actually are very useful. Well detailed in early books (like the ones aimed at users before Linux made everyone system administrators), and now often forgotten.

  5. spelling mistakes, and languages that don’t need variables declared (and don’t warn if you use a variable that you haven’t assigned to) have been responsible for so many bugs in code (other peoples) that I’ve seen that I’ve lost count…
    Which is why (in the old days) that “option explicit none” was at the top of every VBA program I ever did..

Leave a Reply to doragasuCancel reply

Please be kind and respectful to help make the comments section excellent. (Comment Policy)

This site uses Akismet to reduce spam. Learn how your comment data is processed.