eslint-plugin-react
eslint-plugin-react copied to clipboard
no-did-(update|mount)-set-state: `disallow-via-methods` option
[RFC] Adding a new rule to complement the existing no-did-update-set-state
.
This rule will look for any occurrences of this.setState
and check whether the method it is being called from is also called inside componentDidUpdate
.
If this gets a positive feedback I'll also add a doc page for it.
I could see this as an option on the no-did-update-set-state
rule, but the logic is more complex than the original rule, so I decided to keep it separate for now.
I'm not sure this needs to be a separate rule. It would also be nice if it allowed these function calls as callbacks with an option to disallow, like we do with the disallow-in-func
option.
What do other folks think?
I've updated my PR to not create a separate rule for this use case. Instead it uses the logic in both no-did-update-set-state
and no-did-mount-set-state
rules using a new mode disallow-via-methods
.
:+1: / :-1: ? Friendly bump!
Ah yes, that would be preferable
On Wed, Feb 15, 2017, 11:54 AM Jordan Harband [email protected] wrote:
@ljharb commented on this pull request.
In docs/rules/no-did-update-set-state.md https://github.com/yannickcr/eslint-plugin-react/pull/742:
@@ -51,7 +51,7 @@ var Hello = React.createClass({
... -"no-did-update-set-state": [<enabled>, <mode>] +"no-did-update-set-state": [<enabled>, <modeInFunctions>, <modeViaMethods>] Both could be supported with eslint schemas as semver-minor - ie, a "mode" string, and then otherwise, an options object. — You are receiving this because you commented. Reply to this email directly, view it on GitHub <https://github.com/yannickcr/eslint-plugin-react/pull/742>, or mute the thread <https://github.com/notifications/unsubscribe-auth/AAL7zgojwTRK-O-tXmnYP-YhdnJ4BeH8ks5rc1fcgaJpZM4JdpvP> .
I've rebased this, but a few tests are failing.