question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: warn on <lowerCaseFirstLetterInJSX /> when a binding with this name exists in scope

See original GitHub issue

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:

function MyApp() {
  return <lol /> // no such binding in scope, assuming Web Component
}
function MyApp() {
  var i = 0;
  return <i /> // binding exists but `i` is a known HTML tag
}

This would warn:

import { lol } from 'react-bootstrap'

function MyApp() {
  return <lol /> // likely not what you meant
}
var lol = React.createClass(...)

function MyApp() {
  return <lol /> // likely not what you meant
}

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 https://github.com/facebookincubator/create-react-app/issues/299, and @alexzherdev would be interested in implementing it.

Issue Analytics

  • State:open
  • Created 7 years ago
  • Reactions:2
  • Comments:12 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
yannickcrcommented, Jul 31, 2016

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 jsx-pascal-case which is very specific).

0reactions
ljharbcommented, Feb 2, 2022

I’m not sure if this is still relevant.

Unfortunately, we don’t currently have a rule that warns on <foo /> for a foo value that isn’t a valid HTML element - such a rule would be useful, but since React usually warns on it and it’s an obvious mistake, it hasn’t been that necessary.

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?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Rule proposal: warn on <lowerCaseFirstLetterInJSX /> when a ...
If we see <lowerCaseFirstLetterInJSX /> , this is not one of the known HTML tags, and a binding with the same name already...
Read more >
AngularJS: Select not 2-way binding to model - Stack Overflow
I am using a select to show Client names. A user should be able to select an existing client, which will then update...
Read more >
Getting Out of Binding Situations in JavaScript - A List Apart
That function, when called, will take our original method and invoke apply on it, passing: the original object's binding (the variable named object...
Read more >
Binding as Sets of Scopes - Utah School of Computing
Absent a determining s, we can't identify a binding by a single scope, but we can identify it by a set of scopes....
Read more >
4. Execution model — Python 3.6.3 documentation
This rule is subtle. Python lacks declarations and allows name binding operations to occur anywhere within a code block. The local variables of...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found