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]: react/no-unused-prop-types reports false positives if multiple components use the same prop type #3868

Open
2 tasks done
ej612 opened this issue Dec 14, 2024 · 1 comment
Labels

Comments

@ej612
Copy link

ej612 commented Dec 14, 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

I have 2 components that both share the same prop type. The first component doesn't use all props, the second does. The rule reports an error on the second prop claiming it's unused (since it's not used by the first component). It seems that the rule only looks at the first component it can find and doesn't take further components into consideration:

import React from 'react';

interface Props {
    prop1: string,

    // False positive here:
    // 'prop2' PropType is defined but prop is never used eslint(react/no-unused-prop-types)
    prop2: boolean
}

// this component doesn't use prop2
export const Component1 = (props: Props) => {
    return <div title={props.prop1}/>;
};

// this component does
export const Component2 = (props: Props) => {
    return <div title={props.prop1} aria-disabled={props.prop2}/>;
};

Expected Behavior

I would expect the rule to look at all components that use a certain prop type instead of only the first one it can find.

eslint-plugin-react version

7.37.2

eslint version

9.16.0

node version

18.20.5

@ej612 ej612 added the bug label Dec 14, 2024
@ljharb
Copy link
Member

ljharb commented Dec 14, 2024

That seems a strange expectation; each component should be evaluated individually, and they shouldn’t share a Props type if they don’t have the same props signature.

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

2 participants