require-await (Rules) – Eslint 中文开发手册

[
  •   Eslint 中文开发手册

    require-await (Rules) - Eslint 中文开发手册

    没有await表达式的异步函数可能是重构的无意的结果。

    规则细节

    此规则警告不具有await表达式的异步函数。

    此规则的错误代码示例:

    /*eslint require-await: "error"*/
    
    async function foo() {
        doSomething();
    }
    
    bar(async () => {
        doSomething();
    });

    此规则的正确代码示例:

    /*eslint require-await: "error"*/
    
    async function foo() {
        await doSomething();
    }
    
    bar(async () => {
        await doSomething();
    });
    
    function foo() {
        doSomething();
    }
    
    bar(() => {
        doSomething();
    });
    
    // Allow empty functions.
    async function noop() {}

    何时不使用它

    如果您不想通知没有await表达式的异步函数,那么禁用此规则是安全的。

    相关规则

    require-yieldVersion 此规则在 ESLint 3.11.0.Resources 中引入规则资源文档资源

  •   Eslint 中文开发手册
    ]
    转载请保留页面地址:https://www.breakyizhan.com/javascript/34558.html

    posted on 2020-07-05 11:23  MrAit  阅读(437)  评论(0编辑  收藏  举报

    导航