Skip to content
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: jsx-import #155

Closed
sindresorhus opened this issue Feb 15, 2018 · 17 comments
Closed

Rule proposal: jsx-import #155

sindresorhus opened this issue Feb 15, 2018 · 17 comments
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted

Comments

@sindresorhus
Copy link
Owner

sindresorhus commented Feb 15, 2018

Issuehunt badges

Idea from: https://github.com/sindresorhus/refined-github/pull/1089/files#r168391471

When JSX is detected in the source, require the code to import one of the following imports:

  • import React from 'react';
  • import preact from 'preact';
  • import {h} from 'preact';
  • import {h} from 'dom-chef';
  • … (We can fill this list out from need)

And if no JSX is is detect, disallow these imports.

Need suggestions for a better rule name.

Thoughts on the rule?


IssueHunt Summary

fisker fisker has been rewarded.

Backers (Total: $40.00)

Submitted pull Requests


Tips

@fregante
Copy link
Collaborator

fregante commented Feb 15, 2018

I suppose this would have to figure out the pragma (inline and babel's config?) to suggest the right import name (but not the imported module).

Related: https://github.com/jmm/babel-plugin-jsx-pragmatic

@sindresorhus
Copy link
Owner Author

@bfred-it No, I was thinking we just ensure one of the list imports are used. I don't think anyone would use multiple of those, so should be good. No need to overcomplicate it.

@fregante
Copy link
Collaborator

fregante commented Feb 15, 2018

How do you know it's correct though?

Is import {element} from 'dom-chef' valid?
Is import {h} from 'letters' valid?
Is import {h} from 'react-alternative-no-23' valid?

@sindresorhus
Copy link
Owner Author

Is import {element} from 'dom-chef' valid?

No, only named import h.

Is import {h} from 'letters' valid?

Nope, not from the list.

Is import {h} from 'react-alternative-no-23' valid?

Nope.


I think you're misunderstanding, I mean just from the curated list, not random h imports. There are not that many h type modules. I think we can easily cover them all.

@kevva
Copy link

kevva commented Feb 15, 2018

Did you have a look at https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/react-in-jsx-scope.md? Only checks for React though but the pragma can be configured through it's settings.

@sindresorhus
Copy link
Owner Author

@kevva Yup, I'm using it here: https://github.com/xojs/eslint-config-xo-react/blob/6a88098c0a7adac42a3170ca75add48738831b5f/index.js#L37 But I want something that is not just tied to React. Yes you can set the pragma there, but you can't set multiple, and import preact from 'preact'; wouldn't be detected.

@wu-s-john
Copy link
Contributor

I like this rule, it gives users the flexibility to use different libraries corresponding with jsx.

kevva added a commit that referenced this issue Feb 20, 2018
@sindresorhus
Copy link
Owner Author

There's a good starting point in https://github.com/sindresorhus/eslint-plugin-unicorn/pull/162/files if anyone wants to finish it.

@IssueHuntBot
Copy link

@issuehuntfest has funded $40.00 to this issue. See it on IssueHunt

@doniyor2109
Copy link
Contributor

@sindresorhus Hi. I wanted work on it.

@sindresorhus
Copy link
Owner Author

@doniyor2109 Go ahead. Please continue based on #162.

@issuehunt-oss issuehunt-oss bot added the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label May 10, 2019
@sindresorhus
Copy link
Owner Author

This is up for grabs again. If you want to work on this, you can continue where #220 left off. Make sure you address the review comments from that PR.

@fregante
Copy link
Collaborator

fregante commented Oct 1, 2020

@fisker
Copy link
Collaborator

fisker commented Dec 14, 2020

I don't use React, is it mean we can close this?

@fisker
Copy link
Collaborator

fisker commented Nov 18, 2022

@sindresorhus Will you get the bounty back, If I close this directly?

@sindresorhus
Copy link
Owner Author

I can just move it. The bounty here now applies to #1482

@sindresorhus sindresorhus removed the 💵 Funded on Issuehunt This issue has been funded on Issuehunt label Nov 18, 2022
@issuehunt-oss
Copy link

issuehunt-oss bot commented Nov 20, 2022

@sindresorhus has rewarded $36.00 to @fisker. See it on IssueHunt

  • 💰 Total deposit: $40.00
  • 🎉 Repository reward(0%): $0.00
  • 🔧 Service fee(10%): $4.00

@issuehunt-oss issuehunt-oss bot added the 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt label Nov 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement 🎁 Rewarded on Issuehunt This issue has been rewarded on Issuehunt help wanted
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants