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

forbid-prop-types warning shown on Yup validation #2722

Closed
MerlinMason opened this issue Jul 21, 2020 · 6 comments · Fixed by #3326
Closed

forbid-prop-types warning shown on Yup validation #2722

MerlinMason opened this issue Jul 21, 2020 · 6 comments · Fixed by #3326

Comments

@MerlinMason
Copy link

Hey there, a project I work on uses both prop-types and Yup which have a similar syntax.

The following where I'm declaring a Yup validation object:

const formValidation = Yup.object().shape({
    name: Yup.string(),
    customer_ids: Yup.array()
});

Gives me a warning on the line customer_ids: Yup.array() like so:

Prop type `array` is forbidden eslint(react/forbid-prop-types)

I believe this is a bug as this is not a prop type declaration.

@ljharb
Copy link
Member

ljharb commented Jul 21, 2020

This should only warn when object/array/etc is chained off of React.PropTypes or an import/require of the prop-types package.

@nonewcode
Copy link

Working on this

@Parro
Copy link

Parro commented Oct 23, 2020

I have the same problem with this declaration

const validation = yup.object().shape({
  address: yup.object({
    city: yup.string(),
    zip: yup.string(),
  }) 
})

I found the problem started form version 7.20.1, in particular with this commit. From what I understand, it checks recursively for the propTypes definition to be correct. I tried to fix it adding toCallExpression in lib/rules/forbid-prop-types.js a check for the parent to be a propTypes declaration using propsUtil.isPropTypesDeclaration but it works only for the direct children of PropTypes and breaks the recursive behavior.

Maybe I should block the recursive calls in another point?

@rafaelnogueira1
Copy link

I don't know if anyone is still having this problem but i update some of my packages today and got a similar error when running my lint, Prop type array is forbidden.

I was able to fix by changing this:

Yup.array(
      Yup.object().shape({ 
            value: Yup.number()
      })
)

For this:

Yup.array().of(
      Yup.object().shape({ 
            value: Yup.number()
      })
)

@TildaDares
Copy link
Contributor

I'd like to work on this!

@ljharb
Copy link
Member

ljharb commented Jul 6, 2022

Go for it!

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