eslint-plugin-grammar
v2.1.0
Published
EsLint plugin to catch grammar and spelling errors early in development
Readme
eslint-plugin-grammar
An ESLint plugin to check spelling and grammar in JavaScript identifiers, strings, comments, and templates.
Installation
Local (project-wide):
npm install --save-dev eslint-plugin-grammarGlobal:
npm install -g eslint-plugin-grammarBasic Setup
In your ESLint config (.eslintrc or eslint.config.js):
{
"plugins": ["grammar"],
"rules": {
"grammar/grammar-check": ["warn"]
}
}Recommended Configuration
{
"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: trueenables grammar checking at the sentence level, in addition to individual word checks.
Configuration Options
| 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 |
Skipping Numeric Suffixes
To skip terms like md5, sha1, or sha256, add the root words to skipWords:
"skipWords": ["md", "sha"]Example
Here’s an example ESLint config with the plugin enabled:
{
"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
}]
}
}