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

[Bug]: prop-types, triggers on properties called props that are not component props #3861

Open
2 tasks done
rjgotten opened this issue Dec 5, 2024 · 0 comments
Open
2 tasks done
Labels

Comments

@rjgotten
Copy link

rjgotten commented Dec 5, 2024

Is there an existing issue for this?

  • I have searched the existing issues and my issue is unique
  • My issue appears in the command-line and not only in the text editor

Description Overview

The prop-types rule appears to trigger on arbitrary arrow functions inside the lexical scope of a function component, which access any variable named props even if that variable is declared as a parameter of said arrow functions, even if the component itself doesn't even bind the props name and the arrow function thus is not shadowing it.

export const EpisodeTabNavBar: FC<EpisodeTabNavBarProps> = ({ episodeId }) => {
  const { data: episode } = useGetEpisodeQuery({
    "Accept-Language": locale,
    episodeId: episodeId
  }, {
    selectFromResult: props => props.isError // <-- lints error: 'isError' is missing in props validation
      ? { ...props, data: undefined }
      : props
  });
  
  // ...
});

Renaming props to something else, does not error. E.g.

export const EpisodeTabNavBar: FC<EpisodeTabNavBarProps> = ({ episodeId }) => {
  const { data: episode } = useGetEpisodeQuery({
    "Accept-Language": locale,
    episodeId: episodeId
  }, {
    selectFromResult: result => result.isError // <-- no lint error
      ? { ...result, data: undefined }
      : result
  });
  
  // ...
});

Expected Behavior

The prop-types rule should not trigger a lint error on this case. The props variable in question has nothing to do with component props.

eslint-plugin-react version

v7.37.2

eslint version

v8.57.1

node version

v20.12.2

@rjgotten rjgotten added the bug label Dec 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Development

No branches or pull requests

1 participant