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

10 Useful Tasks to Easily Automate During Builds

Common automation approaches to build up your confidence in deploying to production.

Sep 05, 2022

Using Unsplash API to Seed Placeholder Data

With its large collection of (free) professional imagery and easy-to-use developer API, Unsplash is a great tool for generating contextual placeholder images for your application.

Dec 01, 2022