为什么ESLint无法识别我的类箭头函数? [英] Why does ESLint not recognize my class arrow functions?

查看:28
本文介绍了为什么ESLint无法识别我的类箭头函数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循了有关How do I configure ESLint to allow fat arrow class methods将解析器设置为babel-eslint哪些状态的建议。

我安装了它并更新了我的配置文件,如下所示:

{
  "parserOptions": {
    "parser": "babel-eslint",
    "ecmaVersion": 12,
    "sourceType": "module",
    "ecmaFeatures": {
      "jsx": true
    }
  },
  "rules": {
    "semi": "error",
    "indent": ["error", 2],
    "eqeqeq": ["error", "always"],
    "max-depth": ["error", 5],
    "space-before-function-paren": ["error", "never"],
    "template-curly-spacing": ["error", "always"],
    "quotes": ["error", "single", { "allowTemplateLiterals": true }],
    "curly": "error",
    "brace-style": ["error", "1tbs"],
    "space-before-blocks": "error"
  }
}

但是,它仍在中断eslint,出现解析错误,如下所示:

class Person {
  constructor() {
    console.log(this);
    this.hello1();
    this.hello2();
  }

  // breaks eslint, but WHY?

  hello1 = () => {
    console.log(this);
  }
  
  hello2() {
    console.log(this);
  }

}
const P1 = new Person();

突出显示第一个=并显示:

解析错误 意外令牌=

如何进一步解决此问题?ESLint正确应用了此文件中的所有规则,但似乎忽略了解析器选项。

还是其他什么?

我不确定这是否与此处相关:

https://github.com/babel/babel-eslint#note-babel-eslint-is-now-babeleslint-parser-and-has-moved-into-the-babel-monorepo

但我真的不知道那是什么意思。

推荐答案

您的配置文件不正确:

这里有一行:

"parser": "babel-eslint",

什么也不做。遗憾的是,它不会抛出错误并继续使用默认解析器。

完成此操作后,如果正确安装了依赖项的睡觉,则可以开始使用巴别塔解析器。

这篇关于为什么ESLint无法识别我的类箭头函数?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆