Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no-access-state-in-setstate throws on violations #1559

Closed
elmigranto opened this issue Nov 21, 2017 · 8 comments
Closed

no-access-state-in-setstate throws on violations #1559

elmigranto opened this issue Nov 21, 2017 · 8 comments

Comments

@elmigranto
Copy link

elmigranto commented Nov 21, 2017

First of all, thank you everyone, who works on this project, it proved quite useful to me and I am really grateful! ❤️

Now, the problem is that no-access-state-in-setstate rule dies for me when violated. I have versions and stack, but not really sure if any other details are need, please let me know.

Thanks for your help.


Versions:

eslint@4.11.0 
eslint-plugin-markdown@1.0.0-beta.7
eslint-plugin-react@7.5.1 

Stacktrace:

TypeError: Cannot read property 'name' of undefined
    at MemberExpression (<project-root>/node_modules/eslint-plugin-react/lib/rules/no-access-state-in-setstate.js:100:48)
    at listeners.(anonymous function).forEach.listener (<project-root>/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit (<project-root>/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector (<project-root>/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors (<project-root>/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode (<project-root>/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode (<project-root>/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at Traverser.enter (<project-root>/node_modules/eslint/lib/linter.js:959:32)
    at Traverser.__execute (<project-root>/node_modules/estraverse/estraverse.js:397:31)
@jomasti
Copy link
Contributor

jomasti commented Nov 21, 2017

That link is a 404. Could you perhaps paste the source in the issue or produce another link if it is too long?

@elmigranto
Copy link
Author

elmigranto commented Nov 21, 2017

Sorry, didn't notice it was private repo. I removed everything that weren't triggering TypeError, here's what's left after:

var SearchForm = createReactClass({
  render: function () {
    return (
      <div>
        {(function () {
          if (this.state.prompt) {
            return <div>{this.state.prompt}</div>
          }
        }).call(this)}
      </div>
    );
  }
});

Looks like IIFE is the issue, changing div contents to this works:

{
  this.state.prompt
    ? <div>{this.state.prompt}</div>
    : null
}

IDK if this is too "edge-casey" to fix compared to amount of work required, maybe mention in docs then?

@ljharb
Copy link
Member

ljharb commented Nov 22, 2017

wow, i'd never expect to see an IIFE ever again in a world with modules :-) interesting find!

@jer-sen
Copy link

jer-sen commented Dec 25, 2017

@yannickcr do you plan to release a new version soon with this fix ?

@saiichihashimoto
Copy link

I'm getting this issue in 7.6.0 but not 7.5.1. :-)

@ljharb
Copy link
Member

ljharb commented Jan 27, 2018

@saiichihashimoto could you file a new issue with the code that’s causing the crash, along with the stack trace?

@wmertens
Copy link

@saiichihashimoto maybe you got #1657?

@ljharb
Copy link
Member

ljharb commented Jan 29, 2018

v7.6.1 is released; please file a new issue if there's still problems :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

6 participants