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
[codemod] Add optimal-imports
for v5
#27404
Conversation
import TableContext from '@material-ui/core/Table/TableContext'; | ||
import TabScrollButton from '@material-ui/core/Tabs/TabScrollButton'; | ||
import SwitchBase from '@material-ui/core/internal/SwitchBase'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if these should be ignored or not, but I've added them as they were there in the v4.0.0/optimal-imports. I've listed potential solutions to this in the PR description.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good so far. Could use some test what happens if we already have an import from @material-ui/core/colors
or what happens if we have two private imports for the same source.
And the sorting is also not tested. It's not clear to me whether we want to sort alphabetically (the code could be more explicit here instead of .sort()
) or keep the imports as they appeared in the original source.
If people need them sorted, then they can use other lint plugins.
}; | ||
|
||
root.find(j.ImportDeclaration).forEach((path) => { | ||
if (path.value.importKind && path.value.importKind !== 'value') return; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
these are easy to miss.
Going to add a lint rule though that requires braces for single-statement ifs
They have always been private, AFAIK, I would almost advocate for removing the imports, but what we currently do, by ignoring them sounds great too. |
@oliviertassinari the codemod is currently NOT ignoring them, but I could make a list of the imports we want to still support and they can be ignored. |
packages/material-ui-codemod/src/util/allowedPrivateImportsList.js
Outdated
Show resolved
Hide resolved
Co-authored-by: Olivier Tassinari <olivier.tassinari@gmail.com>
private-imports
codemode for v5private-imports
for v5
This comment has been minimized.
This comment has been minimized.
@eps1lon I believe it is good to go now. I've basically just copied the |
It's still unclear from the PR description and name what this codemod is supposed to do. If this is just |
We could rename it to |
private-imports
for v5optimal-imports
for v5
I would ignore that statement since it is based on some false assumptions and statements that are missing context:
We do not migrate all: https://github.com/mui-org/material-ui/blob/4b128c53b895b863e5fd7c4069b53c1598203421/packages/material-ui-codemod/src/v4.0.0/optimal-imports.test/expected.js#L59-L61
The same applies to the v4 version. The problem still stands that we can't codemod private imports. We could only remove these imports which would break the build (which makes the codemod not suitable for But that's probably out-of-scope. For now we just want the same implementation of The problem was that the PR description was incomplete so all I could go off was the name and the name was inaccurate. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Add
optimal-imports
codemod compatible with v5. It is included in thepreset-safe
codemod.