-
-
Notifications
You must be signed in to change notification settings - Fork 32.6k
Fix/codemod top level imports 45051 #46405
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
base: master
Are you sure you want to change the base?
Fix/codemod top level imports 45051 #46405
Conversation
… are not transformed
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.
Thanks for submitting this @AidanLDev! The fix seems correct and the tests as well.
May I ask you to move the expected input and output test content to separate files? Similar to how it's done for other tests. You can create separate files for this test in particular, or add it to the existing files.
Good point, I will update the tests to follow the same style as the other ones :) |
@@ -59,3 +58,7 @@ import { | |||
ClickAwayListener, | |||
ListSubheader, | |||
} from '@mui/material'; | |||
import { createTheme } from '@mui/material/styles'; |
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.
Why is createTheme
moved? Is createTheme
not included on the whitelist
?
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.
Good question, that's right it's not currently in the whitelist so to get the tests passing I moved it outside of the @mui/material
import.
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.
@siriwatknp do you know if this is correct?
|
||
it('should preserve color imports and styles imports', () => { | ||
const input = read('./top-level-imports.test/actual.js'); | ||
const expected = read('./top-level-imports.test/expected.js'); | ||
const actual = transform({ source: input, path: 'test.js' }, { jscodeshift }, {}); | ||
expect(trim(actual)).to.equal( | ||
trim(expected), | ||
'Color imports and styles imports should be preserved', | ||
); | ||
}); | ||
|
||
it('should not transform individual color imports', () => { | ||
const input = read('./top-level-imports.test/actual.js'); | ||
const expected = read('./top-level-imports.test/expected.js'); | ||
const actual = transform({ source: input, path: 'test.js' }, { jscodeshift }, {}); | ||
expect(trim(actual)).to.equal( | ||
trim(expected), | ||
'Individual color imports should not be transformed', | ||
); | ||
}); |
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.
Because we added the imports to the existing actual/expected files, there's no need to add this. Those files are already tested above.
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.
Great point, those two new tests are redundant in that case. I'll remove them
Summary
Fixes #45051 - Fixed logical error in top-level-imports codemod that was incorrectly transforming color imports.
Description
The
v5.0.0/top-level-imports
codemod was incorrectly transforming imports from@mui/material/colors
(e.g.,import { grey } from '@mui/material/colors'
) to@mui/material
(e.g.,import { grey } from '@mui/material'
). This transformation is invalid because color exports likegrey
,blue
, etc. are not available from the main@mui/material
package.Root Cause
The issue was in the whitelist check condition: