简体   繁体   English

experimentalObjectRestSpread在ESLint中不起作用

[英]experimentalObjectRestSpread not working in ESLint

I'm trying to get ESLint to let me use object rest/spread. 我想让ESLint让我使用对象休息/传播。 Despite my best efforts I keep getting this error: 尽管我付出了最大努力,但我仍然遇到此错误

[js] Property assignment expected.

when I hover over the elipses ( ... ) with the red squiggly. 当我用红色波浪形徘徊在elipses( ... )上时。

ALT

My .eslinstrc.json looks like this: 我的.eslinstrc.json看起来像这样:

{
    "extends": "airbnb",
    "plugins": [
        "react"
    ],
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true
        }
    },
    "rules": {
        "no-console": 0
    }
}

I know for sure that the prefs are getting read, as the no-console rule, react plugin, and airbnb style guide is working as expected. 我肯定知道prefs正在读取,因为no-console规则, react插件,并且airbnb样式指南正在按预期工作。

To enable object rest/spread, experimentalObjectRestSpread is the key here (haha), and it seems to be working for other people . 为了启用对象休息/传播, experimentalObjectRestSpread是这里的关键(哈哈), 它似乎适用于其他人 However it refuses to work for me. 但它拒绝为我工作。 I'm at a loss \\o/ 我很茫然\\o/

Update: I'm using Visual Studio Code v1.2.1 更新:我正在使用Visual Studio Code v1.2.1

Am I right assuming you are using vscode? 我假设您使用的是vscode吗? I think the error comes from vscode itself. 我认为错误来自vscode本身。 Otherwise the error message would start with [eslint] instead of [js] . 否则,错误消息将以[eslint]而不是[js] [eslint]

It looks like vscode currently doesn't support object spread operators (see: Issue on Github ). 看起来vscode目前不支持对象扩展运算符(请参阅: Github上的问题 )。

You could disable JavaScript validation with the setting { "javascript.validate.enable": false } . 您可以使用{ "javascript.validate.enable": false }设置禁用JavaScript验证。

Another alternative would be Object.assign : 另一种选择是Object.assign

const foo = {
  a: 1
};
const bar = 'bar';
const res = Object.assign(
    {},
    foo,
    {bar}
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM