In #515, @adrianton3 proposed adding a rule that requires _ prefixes on non-lifecycle methods. His goal is:
I've mistyped
shouldComponentUpdateand other React class members with long names too many times. This rule is intended to prevent that.
I think this could be accomplished with a rule that enforces that methods cannot have a small levenshtein distance from lifecycle methods. I'm not entirely sure what the cutoff should be, but maybe somewhere in the <= 3 range?
Bad:
var Hello = React.createClass({
componentDidUpdaet() {
// this never executes since there's a typo in the method name
},
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
Good:
var Hello = React.createClass({
componentDidUpdate() {
// no typo here!
},
render: function() {
return <div>Hello {this.props.name}</div>;
}
});
If this is _not_ encouraging underscore prefixes but instead attempting to detect typos in lifecycle methods, that sounds like an _excellent_ idea.
Yes, exactly
Most helpful comment
Yes, exactly