Search code examples
javascriptecmascript-6babeljseslintclass-fields

ESLint shows error on class instance property initialized to arrow function


maybe similar to How do I configure ESLint to allow fat arrow class methods

When class method defined as arrow function Eslint highlight error 'method' is not defined. (no-undef). simple example

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

here is not difined 'd'

class method is not defined

my .eslintrc config

{
    "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"
        ]
    }
}

.babelrc

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

Maybe I need to declare some rules?


Solution

  • as mentioned by MinusFour answer, I'm try to run eslint by command line, and I don't see that error.

    My editor was configured wrong. (path to node_modules folder in linter-eslint package for atom was wrong). After I delete this path and restart editor everything is ok.