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

[core] Enforce import * as React #34878

Merged
merged 4 commits into from
Oct 31, 2022
Merged

[core] Enforce import * as React #34878

merged 4 commits into from
Oct 31, 2022

Conversation

da0x
Copy link
Contributor

@da0x da0x commented Oct 24, 2022

It's the way forward: https://twitter.com/dan_abramov/status/1308739731551858689 & facebook/react#18102

As a side note, JSX no longer needs to have React.createElement in the scope thanks to the Babel plugin (for the bundlers that include it) described in: https://reactjs.org/blog/2020/09/22/introducing-the-new-jsx-transform.htm.

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 24, 2022

I got curious, it doesn't seem that we can enforce this with eslint, unfortunately, eslint/eslint#15895.

@oliviertassinari oliviertassinari changed the title Fix typescript import warnings [core] Fix React import Oct 25, 2022
@oliviertassinari oliviertassinari changed the title [core] Fix React import [core] Fix React imports Oct 25, 2022
@oliviertassinari oliviertassinari added core Infrastructure work going on behind the scenes and removed typescript labels Oct 25, 2022
@JoshuaKGoldberg
Copy link

Tip: you use no-restricted-syntax 🙂

{
  "rules": {
    "no-restricted-syntax": [
      "error",
      {
        "message": "Do not import default from React. Use a namespace import (* as) instead.",
        "selector": "ImportDeclaration[source.value=\"react\"] ImportDefaultSpecifier"
        }
    ]
  }
}

@oliviertassinari
Copy link
Member

oliviertassinari commented Oct 25, 2022

@JoshuaKGoldberg Oh nice, I didn't realize we could use an AST selector.

Copy link
Member

@michaldudak michaldudak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency FTW! Thanks for your contribution!

@mui-bot
Copy link

mui-bot commented Oct 25, 2022

Messages
📖 Netlify deploy preview: https://deploy-preview-34878--material-ui.netlify.app/

Details of bundle changes

Generated by 🚫 dangerJS against a6ad3d3

@oliviertassinari oliviertassinari changed the title [core] Fix React imports [core] Enforce import * as React Oct 25, 2022
@mnajdova mnajdova merged commit 2a77a33 into mui:master Oct 31, 2022
daniel-rabe pushed a commit to daniel-rabe/material-ui that referenced this pull request Nov 29, 2022
feliperli pushed a commit to jesrodri/material-ui that referenced this pull request Dec 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Infrastructure work going on behind the scenes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants