Spell checker for JS files
npm install eslint-plugin-spellerThe rule validates the names of variables and functions. Validates the content of strings and comments. It is very useful in detecting potential typos, often unconscious and difficult to detect organoleptically, which unfortunately often lead to errors in code evaluation (once you use the correct name, a few lines later you make a typo). Applying this rule also increases code quality.
You'll first need to install ESLint:
```
$ npm i eslint --save-dev
Next, install eslint-plugin-speller:
``
$ npm install eslint-plugin-speller --save-dev
Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-speller globally.
The plugin uses nspell (hunspell compatible spell checker). By default, dictionary-en-us is used. If you want use other language you must install additional dictionaries from https://github.com/wooorm/dictionaries.
For example, if you want to use Polish, you should install the dictionary-pl package:
``
$ npm install dictionary-pl --save-dev
Add speller to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
`json`
{
"plugins": ["speller"]
}
This plugin has only one rule. Enter the following configuration:
`json`
{
"rules": {
"speller/speller": "warn"
}
}
Examples of incorrect code for this rule:
`js`
var incorrrectVariable = "This is incorrect variable name";
`js`
var incorrectLiteral = "This is incorrect littteerall";
`js`
var incorrectComment = "This is incorrect comment"; // Incorrrecct commment
Examples of correct code for this rule:
`js`
var correctVariable = "This is correct variable";
`js`
var correctLiteral = "This is correct literal";
`js`
var correctComment = "This is correct comment"; // correct comment
This rule accepts a single options argument:
- Set the comments option to false if you want disable linting a comments (line or block). Default is true.literals
- Set the option to false if tou want disable linting a literals (simple Literals or Template Literals). Default is trueidentifiers
- Set the option to false if you want disable linting a identifiers (eg. name of variables or functions). Default is true.dictionary
- Set the option to the name of the npm dictionary package that is compatible with nspell. A list of dictionaries is available here -> https://github.com/wooorm/dictionaries. You must install the additional package on your own. The default is dictionary-en-us - you don't have to install it separately. It accepts Array or String.customDictionary
- Set the option to a list of your own words that do not appear in the dictionary.attachItWords
- Set the option to false if you want disable attach IT words from speller-it-words packagesuggest
- Set the option to false if you want disable suggest similar wordcache
- Set the option to false if you want disable cache result of word spelling and suggest similar word
#### Example option:
`json`
{
"comments": true,
"literals": true,
"identifiers": true,
"dictionary": ["dictionary-en-us", "dictionary-pl"],
"customDictionary": ["yourcustomword"],
"attachItWords": true,
"suggest": true,
"cache": true
}
#### Example configuration:
`json``
"plugins": [
"speller"
],
"rules": {
"speller/speller": ["warn",
{
"comments": true,
"literals": true,
"identifiers": true,
"dictionary": ["dictionary-en-us", "dictionary-pl"],
"customDictionary": ["yourcustomword"],
"attachItWords": "true",
"suggest": true,
"cache": true
}
]
}
If you like typos or incomprehensible variable names, don't use this rule.
The rule uses the nspell package, which is responsible for checking the existence of a word in the dictionary. Thanks to wooorm.