An eslint plugin to enforce method or function name conforms to conventions.
You'll first need to install ESLint:
npm i eslint --save-devNext, install eslint-plugin-function-name:
npm install eslint-plugin-function-name --save-devAdd function-name to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:
{
"plugins": [
"function-name"
],
"rules": {
"function-name/starts-with-verb": "error"
}
}Function is always do something, so it should start with a verb and to avoid confusion with variables.
π Examples of incorrect code for this rule:
function cat(fish) {}
function dog(distance) {}π Examples of correct code for this rule:
function feedCat(fish) {}
function walkDog(distance) {}interface IOptions {
whitelist: string[];
blacklist: string[];
}.eslintrc.js
{
"rules": {
"function-name/starts-with-verb": ["error", {
"whitelist": ["success"],
"blacklist": ["init"]
}]
}
}π Examples of incorrect code for this rule:
// ..."blacklist": ["init"]...
const foo = {
init() {},
}π Examples of correct code for this rule:
// ..."whitelist": ["success"]...
const foo = {
success() {},
}yarn β bun