eslint-plugin-react icon indicating copy to clipboard operation
eslint-plugin-react copied to clipboard

no-did-(update|mount)-set-state: `disallow-via-methods` option

Open avaly opened this issue 8 years ago • 5 comments

[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.

avaly avatar Aug 05 '16 12:08 avaly

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?

lencioni avatar Aug 07 '16 17:08 lencioni

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.

avaly avatar Aug 22 '16 15:08 avaly

:+1: / :-1: ? Friendly bump!

avaly avatar Aug 30 '16 10:08 avaly

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>
.

lencioni avatar Feb 15 '17 20:02 lencioni

I've rebased this, but a few tests are failing.

ljharb avatar Oct 10 '22 03:10 ljharb