Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Lint against imported lowercase components #299

Closed
gaearon opened this issue Jul 30, 2016 · 15 comments
Closed

Lint against imported lowercase components #299

gaearon opened this issue Jul 30, 2016 · 15 comments

Comments

@gaearon
Copy link
Contributor

gaearon commented Jul 30, 2016

If you import something lowercase from a package and then use it in JSX we can be confident you didn't mean a web component.

We should warn in this case. This should probably be a rule in eslint-plugin-react.

@alexzherdev
Copy link
Contributor

alexzherdev commented Jul 30, 2016

I'd love to take a stab at this. @gaearon do you know if it's easy to get eslint-plugin-react maintainers to accept new rules into the repo? EDIT: oh, I see there can be local rules defined in the project.
Also by 'something lowercase' do you mean completely lowercase or starting with a lowercase letter? React docs are a little bit unclear in this, saying you can start the tag with a capital letter to indicate a React component, but on the other hand use 'lower-case tag names' for DOM elements. It's not clear how camelCase would be treated for instance.

@alexzherdev
Copy link
Contributor

@gaearon
Copy link
Contributor Author

gaearon commented Jul 30, 2016

Hmm, not sure. Here’s what prompted me to create this issue. The code looks like this:

import React, { Component } from 'react';
import './App.css';

class App extends Component {
  render() {
    return <lol />;
  }
}

class lol extends Component {
  render() {
    return <h1>lol</h1>;
  }
}

export default App;

That rule doesn’t catch it.

@gaearon
Copy link
Contributor Author

gaearon commented Jul 30, 2016

To be clear, <lol /> is valid React. It means “use a Web Component called lol”. But this is a super rare use case, and 99% times people don’t mean to use Web Components; they expect their classes to work.

What I propose: if lol exists in the scope, it is very likely the user didn’t mean a web component, and meant lol React component instead. We should warn in this case.

@gaearon
Copy link
Contributor Author

gaearon commented Jul 30, 2016

Also by 'something lowercase' do you mean completely lowercase or starting with a lowercase letter?

Anything starting with a lowercase letter. So camelCase will also work super confusingly.

@gaearon
Copy link
Contributor Author

gaearon commented Jul 30, 2016

@vjeux
Copy link
Contributor

vjeux commented Jul 30, 2016

Beware, there are components like "i" that are likely going to be in scope

@gaearon
Copy link
Contributor Author

gaearon commented Jul 30, 2016

Oh, good catch. This rule should have a good HTML tag whitelist I think, then it would be relatively safe.

@gaearon
Copy link
Contributor Author

gaearon commented Jul 30, 2016

Updated the proposal.

@stephenkingsley
Copy link

I think HTML tag whitelist it a way to solve it. But takes some regex in webpack plugin is a good solution?

@gaearon
Copy link
Contributor Author

gaearon commented Aug 4, 2016

Pretty sure we want to solve it in the linter, not as a webpack plugin.

@giuseppeg
Copy link

Custom elements must contain a hyphen - in the name so <lol /> is invalid* both in React and Web Components world.

[*] inherits from HTMLUnknownElement

@giuseppeg
Copy link

ha. Obviously I didn't read jsx-eslint/eslint-plugin-react#726 – sorry about that :)

@gaearon
Copy link
Contributor Author

gaearon commented Sep 24, 2016

Closing as I don't feel strongly about this.

@gaearon gaearon closed this as completed Sep 24, 2016
@wle8300
Copy link

wle8300 commented Apr 27, 2017

I know this issue is closed, but I'm running into warnings when I import a React component that starts with an underscore.

Shouldn't that be allowed syntax as React component?

@lock lock bot locked and limited conversation to collaborators Jan 22, 2019
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

No branches or pull requests

6 participants