[Bug]: Prop-types rules ignored for lowercase functional components #3806
Open
Description
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
Functional components that start with a lower-case letter (const someComponent = ...
) are ignored when checking the prop-types
rule. This behavior is not observed with similarly named class components.
Several of our codebases lean heavily into React's HoC pattern, resulting in component files that look like:
const someComponent = ({ userId }) => {
// some code
}
someComponent.propTypes = {
userId: PropTypes.string.isRequired,
}
const SomeComponent = compose(
withGlobalContext(['userId']),
React.memo,
)(someComponent);
export default SomeComponent
This worked for years on a much older version of the plugin/eslint, but has since stopped reporting errors on new functional components that follow this pattern. In the above example, changing someComponent
to Test
(or anything that starts with a capital letter) fixes the propTypes linting.
Expected Behavior
prop-types rule is enforced even for lowercase functional components; even if it requires a rule configuration to opt into.
eslint-plugin-react version
v7.35.0
eslint version
v8.57.0
node version
v18.20.3
Activity