Eslint returns 为 ES6 函数分配右值
Eslint returns Assigning to rvalue for ES6 functions
目前我正在使用带有此配置的 eslint:
{
"extends": "google",
"installedESLint": true
}
检查此函数时:
app.get('/', (req, res) => {
console.log(req);
res.send('hello world')
});
我得到:
ESlint: Parsing error: Assigning to rvalue
但是,我的代码运行没有问题。
有人可以解释这个错误的含义以及我做错了什么吗?
可能是 babel 解析器中的一个错误,暂时尝试将箭头函数更改为像这样的经典匿名函数:
app.get('/', function (req, res) {
console.log(req);
res.send('hello world')
});
将此添加到您的 eslint 配置中,您在使用箭头函数语法时不应出现任何错误:
{
"parserOptions": {
"ecmaVersion": 6
}
}
我收到此错误(分配给右值),代码如下:
app.use(async (ctx, next) = > {
await next();
});
这是我的配置文件。我试过将 ecmaVersion 设置为 6、7 和 8。我之前发现我需要将它设置为 8 才能让它识别异步函数。上述模式在使用 koajs 创建 Web 服务器时很常见。
{
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"rules": {
"semi": 2
}
}
目前我正在使用带有此配置的 eslint:
{
"extends": "google",
"installedESLint": true
}
检查此函数时:
app.get('/', (req, res) => {
console.log(req);
res.send('hello world')
});
我得到:
ESlint: Parsing error: Assigning to rvalue
但是,我的代码运行没有问题。
有人可以解释这个错误的含义以及我做错了什么吗?
可能是 babel 解析器中的一个错误,暂时尝试将箭头函数更改为像这样的经典匿名函数:
app.get('/', function (req, res) {
console.log(req);
res.send('hello world')
});
将此添加到您的 eslint 配置中,您在使用箭头函数语法时不应出现任何错误:
{
"parserOptions": {
"ecmaVersion": 6
}
}
我收到此错误(分配给右值),代码如下:
app.use(async (ctx, next) = > {
await next();
});
这是我的配置文件。我试过将 ecmaVersion 设置为 6、7 和 8。我之前发现我需要将它设置为 8 才能让它识别异步函数。上述模式在使用 koajs 创建 Web 服务器时很常见。
{
"parserOptions": {
"ecmaVersion": 7,
"sourceType": "module"
},
"rules": {
"semi": 2
}
}