Home

A CLI Tool for Catching Typos in Code and Content

A handy CLI tool for catching misspellings in any files in your codebase.

I’ve previously discussed using a spell checker in VS Code, but it’s easy to miss misspellings when in the zone. Plus, an extension alone doesn’t protect against other team members misspelling words.

cspell (the library behind the VS Code plugin) also has a CLI that you could use to check files in your repository.

Install cspell

You can install cspell on your machine like so:

npm install -g cspell

Or you could choose to run it directly using the npx command:

npx cspell ...

Checking for Typos

Suppose all your content is in markdown files in your repository. You can check across all your content with a command like this:

cspell **/*.md --exclude node_modules

That will print out a list of files that it matches, along with any misspellings.

Configuring Approved Words

There are a number of options for configuration filenames that are automatically consumed. Supposing you chose cspell.json as our config file, you could then add an array of approved words.

{
"words": [
"changefreq",
"checklinks",
"firstname",
"gtag",
"hbsp",
"HUBSPOT",
"jobtitle",
"keylines",
"lastmod",
"lastname",
"nextjs",
"pageview",
"semibold",
"shortcode",
"shortlink",
"sourcebit",
"Sourcebit",
"stackbit",
"swiper",
"tailwindcss",
"urlset"
]
}

Next Steps

This is as far as I’ve taken it so far — using it manually as needed. Ideally, this would be hooked up to some sort of build or continuous integration process, and would fail the build if any words were misspelled.

Hope this helps you avoid typos in your project!

Let's Connect

Keep Reading

Use a Code Spell Checker

Spell-checking isn't just for documentation.

Mar 01, 2021

When to Check for Broken Links

Explore various methods for checking for broken links and what to consider when applying the approaches to your site.

Apr 19, 2023

Testing storage with Selenium (Node)

How to test for key-value pairs in sessionStorage and localStorage using Selenium Node.

Feb 18, 2021