Spell Checking
Installation
See: Installation
Basic Usage
Example: recursively spell check all JavaScript files in src
JavaScript files
cspell "src/**/*.js"
# or
cspell lint "src/**/*.js"
Check everything
cspell .
# or
cspell "**"
Adding CSpell to an existing project
In the steps below we will create a cspell configuration file and setup a single custom dictionary for the project.
Steps:
1. Create a configuration file.
CSpell can use JSON, Yaml, and JavaScript files for configuration. It automatically searches for one of the following: cspell.json
, cspell.config.yaml
, cspell.config.cjs
.
For now choose to use either JSON or Yaml. Below are examples of each that include a custom dictionary definition. Both of them are equivalent. If you have both, CSpell will look for the .json
file first.
- cspell.json
- cspell.config.yaml
{
"$schema": "https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json",
"version": "0.2",
"dictionaryDefinitions": [
{
"name": "project-words",
"path": "./project-words.txt",
"addWords": true
}
],
"dictionaries": ["project-words"],
"ignorePaths": ["node_modules", "/project-words.txt"]
}
---
$schema: https://raw.githubusercontent.com/streetsidesoftware/cspell/main/cspell.schema.json
version: '0.2'
dictionaryDefinitions:
- name: project-words
path: './project-words.txt'
addWords: true
dictionaries:
- project-words
ignorePaths:
- 'node_modules'
- '/project-words.txt'
These configuration files do three things:
- Define the custom dictionary
project-words
. - Tell the spell checker to use the custom dictionary.
- Tell the spell checker to ignore any files inside of
node_modules
and the fileproject-words.txt
.
2. Add words to the project dictionary
It might take a few iterations to get fully setup, but the process in the same.
Steps:
-
Create the dictionary file
touch project-words.txt
-
Choose a set of files to start with, like all Markdown files,
**/*.md
and run the spell checker.cspell "**/*.md"
-
Look for any directories that need to be ignored and add them to
ignorePaths
. Example:"bin"
- to ignore any directory / file calledbin
."translations/**"
- to ignore all files under thetranslations
directory."packages/*/dist"
- to ignore thedist
directory in each package.
Once you have finished identifying directories and files to be ignored, it is now time to add words to the custom dictionary.
-
Have CSpell populate it with the words from your project.
echo "# New Words" >> project-words.txt
cspell --words-only --unique "**/*.md" | sort --ignore-case >> project-words.txtThis will append all new issues to the end of
project-words.txt
-
Review the words in
project-words.txt
to check for any actual misspellings and remove them (the spell checker already thinks they are wrong). -
Fix spelling issues.
To show the issues and suggestions, use:
cspell --no-progress --show-suggestions --show-context "**/*.md"
-
Repeat the process with the other file types you want to check.
3. Fine-tuning
The following resources can help you with fine-tuning your configurations:
Help
Command: lint
-- Spell Checking
The lint
command is used for spell checking files.
Help
cspell lint --help