Skip to content

Rule prop-types causes crash on nested props #2123

Closed
@remcohaszing

Description

@remcohaszing

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.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions