Skip to content
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

prop-types rule reports for Array.prototype.reduce is missing #2383

Closed
ivalduan opened this issue Aug 16, 2019 · 4 comments
Closed

prop-types rule reports for Array.prototype.reduce is missing #2383

ivalduan opened this issue Aug 16, 2019 · 4 comments

Comments

@ivalduan
Copy link

Similar to #1047 when a propType React.PropTypes.arrayOf(), you shouldn't be prompted to add reduce by eslint.
By extension any Array.prototype method that does not modify the data should be included.

@ivalduan
Copy link
Author

Reproduced with v7.14.2

@ljharb
Copy link
Member

ljharb commented Aug 16, 2019

Agreed, this is a bug

@golopot
Copy link
Contributor

golopot commented Aug 20, 2019

I cannot reproduce this. Can you share a snippet for reproduction?

import React from 'react';
import PropTypes from 'prop-types';

function Foo({ a }) {
  return <p>{a.reduce(() => 5)}</p>;
}

Foo.propTypes = {
  a: PropTypes.arrayOf(PropTypes.string).isRequired,
};

@ivalduan
Copy link
Author

Thought it was simple but it seems like the problem goes in another direction.

I was able to reproduce with the following snippet, it seems to be related with identifier collision when parsing the code, if the destructured variable is named differently than the root prop eslint recognizes well the array and the reduce.

import React from 'react';
import PropTypes from 'prop-types';

function Foo({
  elements: {
    items: elements,
  },
}) {
  return <p>{elements.reduce(() => 5)}</p>;
}

Foo.propTypes = {
  elements: PropTypes.shape({
    items: PropTypes.arrayOf(PropTypes.string).isRequired,
  }).isRequired,
};

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

3 participants