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.
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 ...
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.
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"
]
}
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!