Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysterious ESLint Parsing Error

On line 4 of the following code, ESLint is giving me a parsing error saying:

Unexpected token =

I'm wondering why this is the case? The code runs properly. What am I doing wrong?

import { Component, PropTypes } from 'react';

export default class MainApp extends Component {
  static propTypes = {
    children: PropTypes.any.isRequired
  }

  componentWillMount() {
    require('./styles/main.styl');
  }

  render() {
    return (
      <div>
        {this.props.children}
      </div>
    );
  }
}
like image 961
adrianmc Avatar asked Dec 07 '15 01:12

adrianmc


2 Answers

I was able to fix this by:

1) Install babel-eslint

$ npm i --save-dev babel-eslint

OR

$ yarn add babel-eslint --dev

2) Configure ESLint to use babel-eslint as your parser

Just add "parser": "babel-eslint", to your .eslintrc file.

Sample .eslintrc to use babel-eslint and airbnb's configuration with some custom rules:

{
  "parser": "babel-eslint",
  "extends": "airbnb",
  "rules": {
    "arrow-body-style": "off",
    "no-console": "off",
    "no-continue": "off"
  }
}
like image 192
PaulMest Avatar answered Oct 13 '22 14:10

PaulMest


You cannot have properties inside classes, you can only have methods.

Reference: http://www.2ality.com/2015/02/es6-classes-final.html#inside_the_body_of_a_class_definition

like image 7
Gyandeep Avatar answered Oct 13 '22 14:10

Gyandeep