-
-
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
Rule proposal: warn on <lowerCaseFirstLetterInJSX /> when a binding with this name exists in scope #726
Comments
With Web Components, would you not be importing them, or are they implicitly global? |
They are global. (At least React has no mechanism of using anything other than strings or React components as JSX element types.) |
Gotcha. This seems like it might be more useful as a generic rule that only allows lowercased HTML tag names in JSX, along with a user-provided "allow" list for whatever Web Components they need to use? |
I've looked at the history of jsx-pascal-case, and I think it used to do something similar to what is suggested, but stopped doing it here: #329 If found |
It would requires us to keep an up to date whitelist but I think it should not be too hard to maintain such list. Maybe we could do a generic rule about component naming? (and replace |
What kind of generic rule? |
Validate component naming in JSX (must start with an uppercase letter) and having some options to restrict allowed names (pascalCase for example) |
I’m not sure I understand your proposal. How would you tell between a React component and a Web Component without a whitelist (and/or a heuristic) like in my proposal? |
Web components must have a dash somewhere in their name fyi |
@gaearon Ho, I realize my first message was not very clear. My suggestion was to do your proposal (with the whitelist) and add what does |
I'm not sure if this is still relevant. Unfortunately, we don't currently have a rule that warns on I think such a rule, with an explicit allow list for the web components that users have knowingly globally registered, would be reasonable. It would be most ideal if the list of valid HTML tag names was shared by us and React core - ideally through a common package. @gaearon if you think this rule would still be valuable, would it be possible to make such a list available? @alexzherdev are you still willing to implement this rule, assuming the previous question is a yes? |
React currently treats JSX types starting with lowercase letter as Web Components. This is documented but beginners often miss that section. I think in 99% cases using a Web Component is not what people want, and it trips them bad.
I propose the following heuristic. If we see
<lowerCaseFirstLetterInJSX />
, this is not one of the known HTML tags, and a binding with the same name already exists in scope (e.g. as an import, class, function, etc), we are pretty certain the user meant to use their React component, and not a Web Component.This would not warn:
This would warn:
I think flagging any binding is fair game because even if you do intend to use Web Components, having a variable named the same way in the same file is super confusing and just asking for misinterpretation.
I originally filed this as facebook/create-react-app#299, and @alexzherdev would be interested in implementing it.
The text was updated successfully, but these errors were encountered: