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

Handle ExperimentalRestProperty in no-unused-prop-types

theprivileges opened this issue · comments

The no-unused-prop-type rule will throw an error when trying to iterate through properties in an ObjectPattern , when one of the properties is of type ExperimentalRestProperty .

Example

const selectorFoo = (state) => ({isFetching: false, name: 'Foo', isDeleting: false, deltedId: ''});
const selectorBar = (state) => ({ isFetching: false, name: 'Bar'});
export const mapStateToProps = (state) => {
  const { isFetching: isFetchingFoo, ...restFoo } = selectorFoo(state);
  const { isFetching: isFeatchingBar, ...restBar } = selectorBar(state);
  return {
    isFetchingFoo,
    isFetchingBar,
    ...restFoo,
    ...restBar,
  };
};
  export class MyComponent extends Component {
  render() {
      const {isFetchingFoo, name, isFetchingBar, isDeleting, deletedId} = this.props;
      return (
        <div>
          <span>{isFetchingFoo}</span>
          <span>{isDeleting}</span>
          <span>{isFetchingBar}</span>
          <span>{name}{deletedId}</span>
        </div>
      )
  }
};
MyComponent.propTypes = {
  isFetchingFoo: PropTypes.bool.isRequired,
  isDeleting: PropTypes.bool.isRequired,
  deletedId: PropTypes.number.isRequired,
  name: Proptypes.string.isRequired,
  isFetchingBar: PropTypes.bool.isRequired,
};
export default connect(mapStateToProps)(MyComponent);

Error

TypeError: Cannot read property 'name' of undefined

Culprit

node.properties.forEach(prop => context.report(node, `exclude:${prop.key.name}`));