Skip to content

Rule prop-types causes crash on nested props #2123

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

Closed
remcohaszing opened this issue Jan 7, 2019 · 1 comment
Closed

Rule prop-types causes crash on nested props #2123

remcohaszing opened this issue Jan 7, 2019 · 1 comment
Assignees

Comments

@remcohaszing
Copy link
Contributor

The following code triggers an ESLint crash:

import React from 'react';

export default class extends React.Component {
  onSubmit = () => {
    this.setState((state, { a }) => {
      a.b.c();
      return null;
    });
  };

  render() {
    return null;
  }
}

Stack trace:

AssertionError [ERR_ASSERTION]: Node must be provided when reporting error if location is not provided
    at assertValidNodeInfo (node_modules/eslint/lib/util/report-translator.js:96:9)
    at args (node_modules/eslint/lib/util/report-translator.js:246:9)
    at Object.report (node_modules/eslint/lib/linter.js:720:41)
    at reportUndeclaredPropTypes (node_modules/eslint-plugin-react/lib/rules/prop-types.js:175:17)
    at Program:exit.Object.keys.filter.forEach.component (node_modules/eslint-plugin-react/lib/rules/prop-types.js:193:11)
    at Array.forEach (<anonymous>)
    at Object.Program:exit (node_modules/eslint-plugin-react/lib/rules/prop-types.js:192:81)
    at updatedRuleInstructions.(anonymous function) (node_modules/eslint-plugin-react/lib/util/Components.js:756:75)
    at listeners.(anonymous function).forEach.listener (node_modules/eslint/lib/util/safe-emitter.js:45:58)
    at Array.forEach (<anonymous>)

This is caused by the nested prop in the setState() function. When the nesting is one level less deep, the error goes away. So the following code can be linted just fine:

import React from 'react';

export default class extends React.Component {
  onSubmit = () => {
    this.setState((state, { a }) => {
      a.b();
      return null;
    });
  };

  render() {
    return null;
  }
}

This is probably related to #2095.

@ljharb
Copy link
Member

ljharb commented Jan 16, 2019

This is fixed in master; I'll close it with your test case.

@ljharb ljharb self-assigned this Jan 16, 2019
@ljharb ljharb closed this as completed in 2dd2277 Jan 16, 2019
This was referenced Jan 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants