eslint plugin to enforce preferred spelling of words
i couldn't find any other eslint plugin and i just decided to make this because the others have way too many features for such a one-off thing.
you'll first need to install eslint:
npm i eslint --save-dev
next, install eslint-plugin-prefer-spelling
:
npm install eslint-plugin-prefer-spelling --save-dev
Note
this plugin requires node.js version 18.17.1 or above.
add prefer-spelling
to the plugins section of your .eslintrc
configuration file. you can omit the eslint-plugin-
prefix:
{
"plugins": [
"prefer-spelling"
]
}
then configure the rules you want to use under the rules section.
{
"rules": {
"prefer-spelling/prefer-spelling": ["warn", {
"words": {
"color": "colour",
"canceled": "cancelled"
},
"severity": "warn"
}]
}
}
the rule takes an object with the following properties:
words
: an object where keys are the words to be replaced, and values are their preferred spellings.severity
: the severity level of the rule. can be "error", "warn", or "info". defaults to "warn" if not specified.
{
"rules": {
"prefer-spelling/prefer-spelling": ["error", {
"words": {
"color": "colour",
"favorite": "favourite",
"gray": "grey",
"canceled": "cancelled"
},
"severity": "error"
}]
}
}
this configuration will report an error for uses of "color", "favorite", "gray", and "canceled", suggesting their british english spellings instead.
- does the job
- provides auto-fix suggestions that may be stupid
to run the tests for this plugin that is very dreadful and i really do not want to revisit working this tests because i spent way too much time on it, use the following command:
npm test
contributions are welcome! please feel free to submit a pull request.
this project is licensed under the mit license.