-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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 rules ignored for lowercase functional components #3806
Comments
A component, by definition, MUST have a capital letter as the beginning of its name, including with the HoC pattern. I think you just need to stick to that. |
The usage of a component MUST have a capital letter, but not the definition. Moreover, even if this were strictly true it wouldn't explain the discrepancy in the behavior of the plugin between class and functional components. There is nothing in React that precludes (as bad a pattern as it may be)
|
You're entirely correct, but given the limits of static analysis, we've always enforced the universal practice that everyone follows. For classes, we have In my HOC experience, i'd name them |
We did this for quite some time; its an awful convention. It also doesn't do anything to address the plugin being internally inconsistent in its behavior between class components and functional components based on casing (an arbitrary way to determine behavior, regardless of React's conventions). Of course, this entire exchange has also failed to provide any explanation as to why the plugin doesn't actually work in the way the documentation specifies it should. In other words: if this behavior is intended, why is it necessary? Removing this restriction for the enforcement of prop-types warnings/errors during linting wouldn't negatively affect any other user. |
Fair point. It's necessary because without this distinction, we get too many false positives on non-component functions - making the entire plugin not useful. |
Would it be considered as an opt-in behavior available via a new option on the |
Sorry if I'm not being clear. Without this heuristic, you'll get react-related warnings on thousands of non-component functions in your codebase. |
Is there an existing issue for this?
Description Overview
Functional components that start with a lower-case letter (
const someComponent = ...
) are ignored when checking theprop-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:
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
toTest
(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
The text was updated successfully, but these errors were encountered: