DianaSuvorova / eslint-plugin-react-redux

Enforcing best practices for react-redux

Home Page:https://www.npmjs.com/package/eslint-plugin-react-redux

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

mapStateToProps-no-store throws trying to read 'name'

calinoracation opened this issue · comments

Hit enter way too soon accidentally, but seeing the following stack trace when running the recommended rules over our code. Many thanks for creating this package, looking super forward to using it and wanted to file a few issues I'm seeing running it over our codebase.

TypeError: Cannot read property 'name' of undefined

      at returnNode.type.ObjectExpression.returnNode.properties.reduce (node_modules/eslint-plugin-react-redux/lib/rules/mapStateToProps-no-store.js:23:24)
          at Array.reduce (<anonymous>)
      at checkFunction (node_modules/eslint-plugin-react-redux/lib/rules/mapStateToProps-no-store.js:22:27)
      at VariableDeclaration.node.declarations.forEach (node_modules/eslint-plugin-react-redux/lib/rules/mapStateToProps-no-store.js:37:11)
          at Array.forEach (<anonymous>)
      at VariableDeclaration (node_modules/eslint-plugin-react-redux/lib/rules/mapStateToProps-no-store.js:31:25)a
      at listeners.(anonymous function).forEach.listener (node_modules/eslint/lib/util/safe-emitter.js:47:58)
          at Array.forEach (<anonymous>)
      at Object.emit (node_modules/eslint/lib/util/safe-emitter.js:47:38)
      at NodeEventGenerator.applySelector (node_modules/eslint/lib/util/node-event-generator.js:251:26)

The code that triggered the issue is similar to the below:

export function SampleHeaderComponent({ showDefaultHeader: showHeader, ...rest }) {
  if (showHeader) {
    return <DefaultHeader show />;
  }

  return <FlowHeader {...rest} />;
}

HeaderStyle.defaultProps = defaultProps;
HeaderStyle.propTypes = propTypes;

const mapStateToProps = state => ({
  ...getSomeStateFromASelector(state),
  showDefaultHeader: showDefaultHeader(state),
});

export default compose(
  withRouter,
  connect(mapStateToProps),
)(SampleHeaderComponent);

@calinoracation , thanks a lot for giving this plugin a try. And for the code to repro the issue. This looks like a problem with a spread operator. Will take a look.

Fantastic, thanks so much for looking into these issues!!