Permalink
f7a9dcc Jul 23, 2016
82 lines (59 sloc) 1.33 KB

Enforce React components to have a shouldComponentUpdate method (require-optimization)

This rule prevents you from creating React components without declaring a shouldComponentUpdate method.

Rule Details

The following patterns are considered warnings:

class YourComponent extends React.Component {

}
React.createClass({
});

The following patterns are not considered warnings:

class YourComponent extends React.Component {
    shouldComponentUpdate () {
        return false;
    }
}
React.createClass({
    shouldComponentUpdate: function () {
        return false;
    }
});
React.createClass({
    mixins: [PureRenderMixin]
});
@reactMixin.decorate(PureRenderMixin)
React.createClass({

});

Rule Options

...
"require-optimization": [<enabled>, { allowDecorators: [<allowDecorator>] }]
...
  • enabled: for enabling the rule. 0=off, 1=warn, 2=error. Defaults to 0.
  • allowDecorators: optional array of decorators names to allow validation.

allowDecorators

Sets the allowed names of decorators. If the variable is present in the chain of decorators, it validates

The following patterns are not warnings:

// ['pureRender']
@pureRender
class Hello extends React.Component {}

Example

...
"require-optimization": [2, {allowDecorators: ['customDecorators']}]
...