npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eslint-plugin-async-protect

v3.1.0

Published

Protects against missing await keywords on async functions

Downloads

1,022

Readme

eslint-plugin-async-protect

Async functions are great, especially when combined with the await keyword. That being said it isn't always obvious whether a function is asynchronous or not. It is also relatively easy to forget to stick an await on a function. These can cause dome difficult to locate bugs and can waste significant time.

This plugin tries to prevent some of these problems. The other major benefit is because this encourages a naming convention, these rules can apply across different files.

This ESLint plugin enforces the following:

  • functions defined with the async keyword should have an Async suffix on the name
  • calls to functions with an Async suffix on the name should be called with await

Installation

Package: https://www.npmjs.com/package/eslint-plugin-async-protect

Assuming that you already have ESLint installed, simply run:

npm install --save-dev eslint-plugin-async-protect

Configuration

Within your .eslintrc file you need to include the plugin, and specify the level the rules should apply:

{
   "plugins": [
      "async-protect"
   ],
   "rules": {
       "async-protect/async-suffix": "error",
       "async-protect/async-await": "warn",
   }
}

The general recommendation is to use warn for the async-await rule. This is because for 3rd party code you do not have control over function names, and the plugin may complain at extraneous await keywords.

Rules

async-suffix

This rule enforces that async functions have an Async suffix to their name. Functions not defined as async should not have the suffix. Here are some examples:

valid
const fooAsync = async function() {}
async function fooAsync() {}
class Bar {
   async fooAsync() {}
   foo() {}
}

function foo() {}
const foo = function() {}
invalid
const foo = async function() {}
async function foo() {}
class Bar {
    async foo() {} // invalid
    fooAsync() {}  // invalid
}

function fooAsync() {}
const fooAsync = function() {}

async-await

This rule enforces that all functions with an Async suffix on their name should be called with an await or return. Functions without the suffix should not be called with an await or return.

There are times when you may wish for an async function to run in the background, or where you need to call 3rd party code that doesn't follow the async-suffix naming convention. In that case use // eslint-disable-line async-protect/async-await to disable the rule for that line.

valid
await fooAsync();
return fooAsync();
const result = await fooAsync();
const result = (await fooAsync()).result;
const result = await foo().bar().bazAsync();

const result = foo();
invalid
fooAsync();
const result = fooAsync();
const result = fooAsync().result;
const result = foo().bar().bazAsync();

const result = await foo();