Eslint不允许使用静态类属性 [英] Eslint does not allow static class properties

查看:174
本文介绍了Eslint不允许使用静态类属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在Node 12.14.1上开发API,并使用Eslint来帮助我编写代码.不幸的是,它不允许我设置静态类属性,如下所示:

I'm current developing an API on Node 12.14.1 and using Eslint to help me write the code. Unfortunately it does not allow me to set static class properties as shown below:

class AuthManager {
  static PROP = 'value'
}

给出以下错误:解析错误:意外的令牌= eslint

静态类属性已在JS和Node上得到支持.
如何禁用此规则?

Static class properties are already supported on JS and on Node.
How can this rule be disable?

我还有以下 .eslintrc.json 文件:

{
  "env": {
      "es6": true,
      "node": true
  },
  "extends": "eslint:recommended",
  "globals": {
      "Atomics": "readonly",
      "SharedArrayBuffer": "readonly"
  },
  "parserOptions": {
      "ecmaVersion": 2018,
      "sourceType": "module"
  }
}

推荐答案

带有默认解析器的ESLint目前不支持类字段语法.您可以通过将配置的解析器更改为 babel-eslint 来解决该问题.

ESLint with its default parser does not support class fields syntax for now. You can solve the problem by changing the configured parser to babel-eslint.

npm install --save-dev babel-eslint

// eslintrc.json
{
  "parser": "babel-eslint",
  ...
}

Eslint的默认解析器Espree不支持类字段,因为该语法当前处于第3阶段,并且确定在Espree中仅支持第4阶段的提议.

Eslint's default parser, Espree, does not support class fields because that syntax is currently stage 3, and that it is decided that only stage 4 proposals are to be supported in Espree.

这篇关于Eslint不允许使用静态类属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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