Unexpected token = on first function in a class
pzehle opened this issue · comments
This code works well, is just annoying to see this error all the time.
The problem is, when you create a class in ReactJs, and then create two functions inside this class, the first one will be coloured as an error saying:
Unexpected token = (null)
The second function has no error, is always the first. Note that this are arrow functions.
This code will do in Sublime Text 3 with babel-sublime, babel-linter and ESLint packages installed:
import React, { Component } from 'react'; class MyComponent extends Component { firstFunction = () => { return false; } secondFunction = () => { return false; } thirdFunction = () => { return false; } render() { return( <div> Component </div> ); } } export default MyComponent;
No matter what theme or color scheme are you using, this error will be present. I put a screenshot here so you can see the different color from the first function and the second and so on (no error present in the screenshot because I deactivated it on the linter rules).
I am putting my .eslintrc contents for you to see if something is making this error show up.
{ "parser": "babel-eslint", "ecmaFeatures": { "modules": true, "arrowFunctions": true, "classes": true }, "env": { "node": true, "browser": true, "es6": true, }, "rules": { "no-console": 0, "no-mixed-spaces-and-tabs": 0, "react/prop-types": 0, "react/no-unescaped-entities": 0, "react/no-string-refs": 0, "no-useless-escape": 0, "no-irregular-whitespace": 0, "strict": 0 }, "extends": [ "eslint:recommended", "plugin:react/recommended", ], "parserOptions": { ecmaVersion: 6, ecmaFeatures: { jsx: true, }, sourceType: "module" }, }
Same error here. I am using standard together with eslint and vscode plugins.
Currently using:
"babel-eslint": "^10.1.0",
"eslint": "^6.8.0",
But i've tried eslint 2.9, 2.10.1 with no changes.
My eslintrc.yml:
browser: true
es6: true
node: true
extends:
- 'eslint:recommended'
- 'plugin:react/recommended'
globals:
Atomics: readonly
SharedArrayBuffer: readonly
parser: 'babel-eslint'
parserOptions:
ecmaFeatures:
jsx: true
ecmaVersion: 2018
sourceType: module
plugins:
- react
rules:
indent:
- error
- 2
- SwitchCase: 1
linebreak-style:
- error
- unix
quotes:
- error
- single
semi:
- error
- never
Ok, after 2 days stuggling and a few minutes after posting my message here, I discovered that the problem was caused by standardjs plugin on vscode, nothing to do with eslint.
I've just uninstalled it and the problem is gone.
Thank you for the issue. Now that @babel/eslint-parser
has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.