New Rule Proposal: Consistent async function naming
See original GitHub issuePlease describe what the rule should do:
This rule enforces that async
functions are named with an Async suffix and also that any function named with an Async suffix be marked as async
. It is a common practice for functions that return promises to be named with an Async suffix to indicate to the caller that they should handle a promise. (They either need to await
the result, call .then
, etc.) In fact, this is also the standard naming convention in .NET, which has a similar async/await pattern.
What category of rule is this? (place an “X” next to just one item)
[x] Enforces code style [ ] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about:
Incorrect versions:
async function doSomething() {
// ...
}
function doSomethingElseAsync() {
// ...
}
Correct versions:
async function doSomethingAsync() {
// ...
}
async function doSomethingElseAsync() {
// ...
}
Why should this rule be included in ESLint (instead of a plugin)?
The rule inforces consistency of a very common practice (from even before the async
keyword existed). It is general, library agnostic, and shouldn’t conflict with other rules.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (5 by maintainers)
Top GitHub Comments
Seems fair that you don’t want the core to be so opinionated. @not-an-aardvark’s suggestion and @platinumazure’s example were a great start. However, there are a number of cases to cover:
I expanded the rule a bit to cover all of these cases and it seems to catch all of these:
If you don’t feel something like this should be in the core, then at least this issue serves as an example for other folks who want to follow this async pattern. Thanks!
I agree with @not-an-aardvark I think this is pretty opinionated rule for the core, and should be part of a plugin (or as @platinumazure showed, should just be part of the configuration). Although I’m biased. I hate prefixes and postfixes for variable/function names.