How to Check Typo
Introduction
Let me share something that happened recently: the day after our project went live, the big boss sent over a screenshot. In the screenshot, the label on a search box said: “Search Applicaiton”. So of course, I quickly tracked down where it was, fixed it, and submitted the patch.
Why do we need to fix typos?
- They shouldn’t exist in the first place
- To avoid misleading users
- To prevent unexpected bugs
After submitting this typo fix, I started thinking: can we use a tool to catch these stragglers? I asked ChatGPT, and it recommended CSpell.
What is CSpell
CSpell was originally a VS Code extension. Back when we first started using VS Code, it didn’t have a spell checker. As someone with spelling difficulties, I found this to be a major obstacle, so this extension was created. Later, based on user suggestions, CSpell was separated out from the extension and turned into its own library and CLI tool.
https://cspell.org/
Installing CSpell
Install via npm/yarn/pnpm:
1
npm install --save-dev cspell
I personally chose to install it globally so I can use it from any directory:
1
npm install -g cspell
Create a configuration file (
cspell.config.json
orcspell.config.yaml
)In the official documentation Create a configuration file., you can see the supported formats and locations for config files.
Basic Usage
Command line usage examples
1
cspell .
Specifying multiple file types
1
cspell "src/**/*.{js,ts,vue,jsx}"
Check all
.md
files in the source directory1
cspell 'source/**/*.md'
Run results:
1 | cspell 'source/_posts_i18n/en/*.md' |
Configurations
Read: https://cspell.org/docs/Configuration
The configuration I used:
1 | module.exports = { |
key | for |
---|---|
language | Specify language |
ignorePaths | Ignore directories for checking |
words | Custom vocabulary |
Integrate into workflow
We can integrate cspell at different stages.
For example, prebuild
has the advantage that if the cspell check fails, the build process will be terminated until the error is fixed.
1 | { |
Also try: VS Code extension, which checks spelling errors as you type.
CSpell Bundled Dictionaries - Code Spell Checker
Check Multiple Repos
As mentioned at the beginning, I want to check multiple projects for any remaining typos. To do this, I need to:
- Place all the repositories that need to be checked into a single parent folder;
- Configure
cspell.config.js
in this parent folder; - Run CSpell from this parent folder.
1 | . |