下面的代码:

import React from 'react';
import { Link } from 'react-router';
import { View, NavBar } from 'amazeui-touch';

import * as Pages from '../components';

const {  Home, ...Components } = Pages;

我得到这个eslint错误:

7:16  error  Parsing error: Unexpected token .. Why?

这是我的eslint配置:

{
  "extends": "airbnb",
  "rules": {
    /* JSX */
    "react/prop-types": [1, {
      "ignore": ["className", "children", "location", "params", "location*"]
    }],
    "no-param-reassign": [0, {
      "props": false
    }],
    "prefer-rest-params": 1,
    "arrow-body-style": 0,
    "prefer-template": 0,
    "react/prefer-stateless-function": 1,
    "react/jsx-no-bind": [0, {
      "ignoreRefs": false,
      "allowArrowFunctions": false,
      "allowBind": true
    }],
  }
}

.... .... 有什么问题吗?


当前回答

ESLint 2。x实验性地支持ObjectRestSpread语法,您可以通过在.eslintrc: docs中添加以下内容来启用它

"parserOptions": {
  "ecmaVersion": 6,
  "ecmaFeatures": {
    "experimentalObjectRestSpread": true
  }
},

ESLint 1。X本身不支持扩散操作符,解决这个问题的一种方法是使用babel-eslint解析器。最新的安装和使用说明在项目自述中。

其他回答

我使用typescript,我解决了这个错误更改解析器

....
"prettier/prettier": [
            "error",
            {
                .....
                "parser": "typescript",
                .....
            }
        ],
....

最初,解决方案是提供以下配置,因为对象解构曾经是一个实验特性,默认情况下不支持:

{
  "parserOptions": {
    "ecmaFeatures": {
      "experimentalObjectRestSpread": true
    }
  }
}

从版本5开始,该选项已弃用。

现在只要声明一个ES的新版本就足够了:

{
  "parserOptions": {
    "ecmaVersion": 2018
  }
}

在我的情况下(我使用Firebase云函数),我打开.eslintrc.json并更改:

"parserOptions": {
  // Required for certain syntax usages
  "ecmaVersion": 2017
},

to:

"parserOptions": {
  // Required for certain syntax usages
  "ecmaVersion": 2020
},

如果你有一个使用husky运行eslint的预提交任务,请继续阅读。我尝试了大多数关于parserOptions和解析器值的答案,其中我的实际问题是关于我所使用的节点版本。

我当前的节点版本是12.0.0,但husky以某种方式使用了我的nvm默认版本(尽管我的系统中没有nvm)。这似乎是哈士奇本身的问题。所以:

我删除了$HOME/。nvm文件夹,当我之前删除nvm时没有删除。 验证节点是最新的,并做了适当的解析器选项。 它开始工作了!

我使用eslint进行云功能(开发环境:flutter 2.2.3)。

在我的情况下,.eslintrc.json不存在,所以我必须更新.eslintrc.js文件,包括parserOptions: {"ecmaVersion": 2020,},属性在文件的末尾。我更新的.eslintrc.js文件是这样的:

module.exports = {
  root: true,
  env: {
    es6: true,
    node: true,
  },
  extends: [
    "eslint:recommended",
    "google",
  ],
  rules: {
    quotes: ["error", "double"],
  },
  
  // Newly added property
  parserOptions: {
    "ecmaVersion": 2020,
  },
};