Skip to content

Starts With Verb

Suggestion
small-rules/starts-with-verb

Require function and method names to begin with a verb.

Rationale

A function does something, so its name should say what. getUserProfile() reads as an action at the call site; userProfile() reads like a value, and you have to check whether it’s one.

It leaves names with no lowercase prefix alone, such as UserProfile components. It also backs off where you don’t get to pick the name: override members, getters and setters, constructors, computed keys, and keys of an object whose shape comes from elsewhere. That covers objects passed straight into a call or new, checked with satisfies, or annotated with an imported type. Add your own words with allowList, and exclude words with denyList.

Diagnostic Messages

notVerb
'{{name}}' should begin with a verb, but '{{prefix}}' is not one.

Configuration

This rule accepts one options object after the severity.

allowListOptional

No description available.

denyListOptional

No description available.

{
"jsPlugins": [
"@pobammer-ts/small-rules"
],
"rules": {
"small-rules/starts-with-verb": [
"error",
{
"allowList": [
"value"
],
"denyList": [
"value"
]
}
]
}
}

Examples

Noun function name
function userProfile(id: string): string {
return id;
}
Verb function name
function getUserProfile(id: string): string {
return id;
}