4

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?

Bergi
  • 630,263
  • 148
  • 957
  • 1,375
n06rin
  • 173
  • 2
  • 9
  • 1
    ES6 classes do not have instance variables, which is what `d` is here. –  Aug 17 '17 at 03:47
  • arrow functions don't make sense in a `class` - just like setting `Something.prototype.somefunction = () => {}` makes no sense – Jaromanda X Aug 17 '17 at 03:48
  • @torazaburo - the `class` syntax doesn't provide for instance variables, but the resulting classes can have them if created in methods. (Just being picking about wording.) (So my wording is probably wrong too.) – nnnnnn Aug 17 '17 at 03:50
  • Do you get the error if you run ESLint in the CLI? Sounds more like your editor just doesn't pick up the `.eslintrc`. – loganfsmyth Aug 17 '17 at 16:00
  • In `.eslintrc` add `"ecmaVersion": 7,` under `parserOptions`. – Greg K Mar 22 '18 at 12:15

2 Answers2

3

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.

n06rin
  • 173
  • 2
  • 9
  • was running into same thing with VSCode, was using ESLint plugin, reinstalled the plugin and now the linter in the editor behaves in pair with what I see in the terminal. – wiherek May 31 '18 at 12:06
0

This is something that hasn't made its way into Javascript yet. It's available as an experimental plugin with babel, so you'll need to change the default parser for eslint with babel-eslint.

MinusFour
  • 13,913
  • 3
  • 30
  • 39
  • yes, you're right. And in .eslint config file I set parser to babel-eslint (you can see it on question). But it didn't help. – n06rin Aug 17 '17 at 04:17
  • @n06rin, I just noticed that. It works fine for me though, which version of eslint and babel-eslint are you using? – MinusFour Aug 17 '17 at 04:19
  • I'm using eslint@4.4.1 and babel-eslint@7.2.3 – n06rin Aug 17 '17 at 04:25
  • @n06rin, i have the same packages then. Try running it directly from the command line and not from your editor. – MinusFour Aug 17 '17 at 04:31
  • interesting, when I'm run eslint from command line, that didn't show that error. I assume something wrong with my editor. Thanks. – n06rin Aug 17 '17 at 04:52
  • @n06rin, it must be running a global version of `eslint` that is outdated, try updating both (eslint and babel-eslint) globally. – MinusFour Aug 17 '17 at 04:53