Skip to content

sort-prop-types throws an error for {sortShapeProp: true} if shape is not object literal #1668

@justinanastos

Description

@justinanastos

Example and use case:

import ChildComponent from './child-component';

SomeComponent.propTypes = {
  childProps: PropTypes.shape(
    ChildComponent.propTypes,
  ),
};

This will cause the following error to be thrown:

TypeError: Cannot read property 'reduce' of undefined
    at checkSorted ([localpath]/node_modules/eslint-plugin-react/lib/rules/sort-prop-types.js:80:20)
    at CallExpression ([localpath]/node_modules/eslint-plugin-react/lib/rules/sort-prop-types.js:166:9)
    at listeners.(anonymous function).forEach.listener ([localpath]/node_modules/eslint/lib/util/safe-emitter.js:47:58)
    at Array.forEach (<anonymous>)
    at Object.emit ([localpath]/node_modules/eslint/lib/util/safe-emitter.js:47:38)
    at NodeEventGenerator.applySelector ([localpath]/node_modules/eslint/lib/util/node-event-generator.js:251:26)
    at NodeEventGenerator.applySelectors ([localpath]/node_modules/eslint/lib/util/node-event-generator.js:280:22)
    at NodeEventGenerator.enterNode ([localpath]/node_modules/eslint/lib/util/node-event-generator.js:294:14)
    at CodePathAnalyzer.enterNode ([localpath]/node_modules/eslint/lib/code-path-analysis/code-path-analyzer.js:608:23)
    at Traverser.enter [as _enter] ([localpath]/node_modules/eslint/lib/linter.js:1006:32)
    at Traverser._traverse ([localpath]/node_modules/eslint/lib/util/traverser.js:132:14)
    at Traverser._traverse ([localpath]/node_modules/eslint/lib/util/traverser.js:147:30)
    at Traverser._traverse ([localpath]/node_modules/eslint/lib/util/traverser.js:144:34)
    at Traverser._traverse ([localpath]/node_modules/eslint/lib/util/traverser.js:147:30)
    at Traverser._traverse ([localpath]/node_modules/eslint/lib/util/traverser.js:147:30)
    at Traverser._traverse ([localpath]/node_modules/eslint/lib/util/traverser.js:144:34)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions