Babel.js ESLint显示初始化为箭头函数的类示例属性错误

insrf1ej  于 2022-12-16  发布在  Babel
关注(0)|答案(2)|浏览(173)

可能类似于How do I configure ESLint to allow fat arrow class methods
当类方法定义为箭头函数时,Eslint突出显示错误“方法”未定义。(no-undef)。简单示例

class abc {
  d = () => {
    // method body
  }
}

此处未定义“d”

我的.eslintrc配置

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": [
      "eslint:recommended",
      "plugin:flowtype/recommended"
    ],
    "parser": "babel-eslint",
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react",
        "flowtype"
    ],
    "rules": {
        "indent": [
            "error",
            2
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "error",
            "always"
        ]
    }
}

巴伯尔

{
  "presets": ["react", "es2015", "stage-1", "flow"]
}

也许我需要宣布一些规则?

dw1jzc5e

dw1jzc5e1#

如MinusFour答案所述,我尝试通过命令行运行eslint,但没有看到该错误。
我的编辑器配置错误。(指向Atom的linter-eslint包中node_modules文件夹的路径错误)。在我删除此路径并重新启动编辑器后,一切正常。

h7wcgrx3

h7wcgrx32#

This is something that hasn't made its way into Javascript yet。它是babel的一个实验插件,所以你需要用babel-eslint来修改eslint的默认解析器。

相关问题