ESlint:Promise 和 Async 的配置

Dev*_*Bab 3 javascript eslint

与 ESLint 一起使用的配置让它接受两个代码,如:

return new Promise(..)
Run Code Online (Sandbox Code Playgroud)

async function() {...}
Run Code Online (Sandbox Code Playgroud)

这在 Node.js 中使用

无论 ES6 2017 的配置如何.... 我一直有类似的错误:

'Promise' 未定义 no-undef

或者

解析错误:意外的令牌函数

谢谢 !

Bri*_*rns 10

FWIW,eslint 需要在解析器和环境部分中指定 ES6,例如

{
    "parserOptions": {
        "ecmaVersion": 9,
        "sourceType": "module",
        "ecmaFeatures": {
            "jsx": true,
            "modules": true
        }
    },
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": "eslint:recommended",
    ...
Run Code Online (Sandbox Code Playgroud)

有关讨论,请参阅https://github.com/eslint/eslint/issues/9812