Finding typos in the project
This tool turned out to be CSpell. If you write code in Visual Studio Code, then you are already using it. CSpell positions itself as a code speller, but it can also spell regular texts. Let's connect it to the project.
Connection
npm i --save-dev cspell
npm i --save-dev @cspell/dict-ru_ru
IN package.json
:
{
"scripts": {
"cspell-lint": "cspell ** --cache --show-suggestions --no-progress",
"cspell-sort": "LC_ALL=C sort -f -u cspell_custom_words.txt -o cspell_custom_words.txt"
}
}
Create a settings file in the project root cspell.json
:
{
"version": "0.2",
"language": "en,ru",
"dictionaryDefinitions": [
{
"name": "cspell-custom-words",
"path": "./cspell_custom_words.txt",
"addWords": true
}
],
"dictionaries": [
"cspell-custom-words",
"typescript",
"html"
],
"import": ["@cspell/dict-ru_ru/cspell-ext.json"],
"ignorePaths": [
"node_modules",
"deploy",
"dist",
"assets"
]
}
Unfortunately, not all words are available in CSpell dictionaries. Unknown words will need to be added to your own dictionary or connected additional dictionarywe will consider this a kind of “use tax”.
In the root of the project for our own dictionary we create a file cspell_custom_words.txt
:
контрол
промис
дженерик
...
The creation of this dictionary can be significantly speeded up by running the command in the project:
cspell ** --words-only | sort -uf > cspell_custom_words.txt
Removing typos from cspell_custom_words.txt
– your dictionary is ready!
Another interesting thing is that it is possible to display typos with context, the parameter --show-context
.
Plus, you can dump all typos into JSON: cspell "**" --reporter @cspell/cspell-json-reporter
.
Next, add a precommit hook to your liking and connect it to CI.