Skip to content
This repository has been archived by the owner on Aug 18, 2021. It is now read-only.

Unexpected token = on first function in a class #704

Closed
pzehle opened this issue Oct 16, 2018 · 4 comments
Closed

Unexpected token = on first function in a class #704

pzehle opened this issue Oct 16, 2018 · 4 comments

Comments

@pzehle
Copy link

pzehle commented Oct 16, 2018

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).

lbvl0

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" }, }

@Redsandro
Copy link

Is this a regression to #312?

@phvelozo
Copy link

phvelozo commented Apr 17, 2020

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

@phvelozo
Copy link

phvelozo commented Apr 17, 2020

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.

@kaicataldo
Copy link
Member

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.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants