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

Strange behavior of forbid-prop-types for nested prop types #2945

Closed
zfletch opened this issue Mar 12, 2021 · 1 comment
Closed

Strange behavior of forbid-prop-types for nested prop types #2945

zfletch opened this issue Mar 12, 2021 · 1 comment

Comments

@zfletch
Copy link

zfletch commented Mar 12, 2021

I'm running into some unexpected behavior with the forbid-prop-types rule and nested prop types (e.g. arrayOf(object)). It looks like there's either a bug that manifests differently depending on how prop types are imported or there are two different bugs. Similar issues have been reported (#2657, #2662), but I'm re-reporting this because they're marked as fixed by 997a99f and this is still happening.

I'm including two examples along with my configuration below. The version of eslint is 7.20.0 and the version of eslint-plugin-react is 7.22.0.

Example 1

import React from './React';

import { arrayOf, object } from 'prop-types';

const App = ({ foo }) => (
  <div>
    Hello world {foo}
  </div>
);

App.propTypes = {
  foo: arrayOf(object)
}

export default App;
/tmp/test/src/App.js
  13:3  error  Prop type `undefined` is forbidden  react/forbid-prop-types

✖ 1 problem (1 error, 0 warnings)

Here, eslint is correctly returning an error, but the description should say "Prop type `object`", not "Prop type `undefined`".

Example 2

import React from './React';

import PropTypes, { arrayOf } from 'prop-types';

const App = ({ foo }) => (
  <div>
    Hello world {foo}
  </div>
);

App.propTypes = {
  foo: arrayOf(PropTypes.object)
}

export default App;
✨  Done in 0.77s.

In this case, eslint is incorrectly returning no errors.

Configuration

  "rules": {
    "react/forbid-prop-types": ["error", {
      "forbid": ["object"]
    }]
  },
@ljharb
Copy link
Member

ljharb commented Mar 12, 2021

Both of those are indeed bugs.

ljharb added a commit to ljharb/eslint-plugin-react that referenced this issue Feb 22, 2022
ljharb added a commit to ljharb/eslint-plugin-react that referenced this issue Feb 22, 2022
@ljharb ljharb closed this as completed in 2cca260 Feb 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

No branches or pull requests

2 participants