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": [

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

Creating Parity Between CI and Jamstack Deployment Process

You can get to production faster by separating CI and build/deployment process. But there’s risk in it. Here are two approaches to help with the decision.

Jul 01, 2022

How to Upload Jest Image Snapshot Diffs to S3

Add snapshots from failed to S3 to enable running jest-image-snapshot on continuous integration server.

Jan 26, 2022