EsLint plugin to catch grammar and spelling errors early in development
npm install eslint-plugin-grammarAn ESLint plugin to check spelling and grammar in JavaScript identifiers, strings, comments, and templates.
Local (project-wide):
``bash`
npm install --save-dev eslint-plugin-grammar
Global:
`bash`
npm install -g eslint-plugin-grammar
In your ESLint config (.eslintrc or eslint.config.js):
`json`
{
"plugins": ["grammar"],
"rules": {
"grammar/grammar-check": ["warn"]
}
}
`json`
{
"plugins": ["grammar"],
"rules": {
"grammar/grammar-check": [1, {
"comments": true,
"strings": true,
"identifiers": true,
"templates": true,
"sentences": true,
"lang": "en_US",
"skipWords": ["dict", "aff", "pdf", "utils"],
"skipIfMatch": ["http://[^s]*", "^[-\\w]+\/[-\\w\\.]+$"],
"skipWordIfMatch": ["^foobar.*$"],
"minLength": 3
}]
}
}
> ℹ️ sentences: true enables grammar checking at the sentence level, in addition to individual word checks.
| Option | Type | Default | Description |
|-------------------------------|-----------|-----------|-------------|
| comments | Boolean | true | Spell-check comments |strings
| | Boolean | true | Spell-check strings |identifiers
| | Boolean | true | Spell-check variable and function names |templates
| | Boolean | true | Spell-check ES6 template literals |sentences
| | Boolean | false | Enable sentence-level grammar checking |ignoreRequire
| | Boolean | false | Skip require() calls |enableUpperCaseUnderscoreCheck
| | Boolean | false | Skip UPPER_CASE identifiers |enablePascalCase
| | Boolean | false | Skip PascalCase identifiers |lang
| | String | "en_US" | Supported: en_US, en_CA, en_AU, en_GB |langDir
| | String | "" | Path to custom dictionary files |skipWords
| | String[] | [] | Words to ignore |skipIfMatch
| | RegExp[] | [] | Skip entire node if matched |skipWordIfMatch
| | RegExp[] | [] | Skip individual words if matched |minLength
| | Number | 1 | Ignore words shorter than this length |debug
| | Boolean | false | Enable debug logging |confidence
| | Number | 0.1 | Minimum confidence threshold for grammar suggestions |
To skip terms like md5, sha1, or sha256, add the root words to skipWords:
`json`
"skipWords": ["md", "sha"]
Here’s an example ESLint config with the plugin enabled:
`json``
{
"plugins": ["grammar"],
"rules": {
"grammar/grammar-check": [1, {
"comments": true,
"strings": true,
"identifiers": true,
"templates": true,
"sentences": true,
"lang": "en_US",
"skipWords": ["dict", "aff", "gramma", "utils"],
"minLength": 3
}]
}
}