Skip to content

Disabling eslint rule for react/forbid-foreign-prop-types does not work on all references #2328

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

Closed
noratarano opened this issue Jun 25, 2019 · 6 comments

Comments

@noratarano
Copy link

noratarano commented Jun 25, 2019

Summary of the issue

Here's a snippet from the code in our repo for prop types hoisting in an HOC:

function withBreakpoint<C extends React.ComponentType<any>>(WrappedComponent: C) {
  // ...

  // eslint-disable-next-line react/forbid-foreign-prop-types
  if (WrappedComponent.propTypes) {
    // eslint-disable-next-line react/forbid-foreign-prop-types
    const { currentBreakpoint, breakpoints, ...restPropTypes } = WrappedComponent.propTypes;
    WithBreakpoint.propTypes = restPropTypes as PropTypes.ValidationMap<Props>;
  }

  // ...
}

Even though linting on the the first reference of WrappedComponent.propTypes is disabled, it fails linting.

Screenshot:

Screen Shot 2019-06-24 at 7 38 32 PM

Result in CI:

133:24  error    Using propTypes from another component is not safe because they may be removed in production builds  react/forbid-foreign-prop-types

Attempted solutions

❌ Didn't work

  • Surrounded the statement with /* eslint-disable react/forbid-foreign-prop-types */ and /* eslint-enable react/forbid-foreign-prop-types */
  • // eslint-disable-next-line to disable all rules for that line

✅ Worked

  • Added /* eslint-disable react/forbid-foreign-prop-types */ at the top of the file

cc @ljharb

@ljharb
Copy link
Member

ljharb commented Jun 25, 2019

That should certainly work. What's your eslint config and versions?

@yannickcr
Copy link
Member

yannickcr commented Jun 26, 2019

I was not able to reproduce the issue on the above snipped using [email protected] and [email protected].

@ljharb
Copy link
Member

ljharb commented Jun 26, 2019

Closing pending confirmation of version numbers used.

@ljharb ljharb closed this as completed Jun 26, 2019
@ljharb
Copy link
Member

ljharb commented Jul 1, 2019

This was happening with eslint 5; reopening.

@ljharb ljharb reopened this Jul 1, 2019
@yannickcr
Copy link
Member

Was not able to reproduce it with ESLint@5 either, do you have more information @ljharb?

@ljharb
Copy link
Member

ljharb commented Jan 2, 2022

Closing.

Happy to reopen and fix ASAP with a repro repo, or a failing test, but it's unlikely this continues to be a problem.

@ljharb ljharb closed this as completed Jan 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants