Permalink
9ba1910 Dec 21, 2015
@yannickcr @hamiltondanielb
60 lines (44 sloc) 1.13 KB

Enforce ES5 or ES6 class for React Components (prefer-es6-class)

React offers you two way to create traditional components: using the ES5 React.createClass method or the new ES6 class system. This rule allow you to enforce one way or another.

Rule Options

...
"prefer-es6-class": [<enabled>, <mode>]
...

always mode

Will enforce ES6 classes for React Components. This is the default mode.

The following patterns are considered warnings:

var Hello = React.createClass({
  render: function() {
    return <div>Hello {this.props.name}</div>;
  }
});

The following patterns are not considered warnings:

class Hello extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

never mode

Will enforce ES5 classes for React Components

The following patterns are considered warnings:

class Hello extends React.Component {
  render() {
    return <div>Hello {this.props.name}</div>;
  }
}

The following patterns are not considered warnings:

var Hello = React.createClass({
  render: function() {
    return <div>Hello {this.props.name}</div>;
  }
});