-
-
Notifications
You must be signed in to change notification settings - Fork 32.8k
[material-ui][Divider] Add codemod for light prop removal
#40947
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
Merged
Merged
Changes from 6 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
a02819c
fix
sai6855 a02e604
Merge branch 'master' into codemod-divider
sai6855 cbd2912
fix jsx
sai6855 d920ddd
fix jsx
sai6855 af6fcea
Add tests for divider-props transformation
sai6855 f673404
update readme
sai6855 1ec3ecc
add codemod for sx prop
sai6855 c6ca8b7
add codemod for sx prop
sai6855 d57eb35
add codemod for sx prop
sai6855 f7ed243
Merge branch 'master' into codemod-divider
sai6855 3b3b184
add migration guide
sai6855 360f5ef
proptypes
sai6855 4e4af83
revert-theme.actual
sai6855 78fc792
update-readme
sai6855 0ed42b5
Merge branch 'master' into codemod-divider
sai6855 35417d9
docs:api
sai6855 b567e79
polish details
sai6855 cf3ec7c
Apply suggestions from code review
DiegoAndai File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
packages/mui-codemod/src/deprecations/divider-props/divider-props.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import findComponentJSX from '../../util/findComponentJSX'; | ||
|
|
||
| /** | ||
| * @param {import('jscodeshift').FileInfo} file | ||
| * @param {import('jscodeshift').API} api | ||
| */ | ||
| export default function transformer(file, api, options) { | ||
| const j = api.jscodeshift; | ||
| const root = j(file.source); | ||
| const printOptions = options.printOptions; | ||
|
|
||
| findComponentJSX(j, { root, componentName: 'Divider' }, (elementPath) => { | ||
| elementPath.node.openingElement.attributes = elementPath.node.openingElement.attributes.filter( | ||
| (attr) => { | ||
| if (attr.type === 'JSXAttribute' && attr.name.name === 'light') { | ||
| return false; | ||
| } | ||
| return true; | ||
| }, | ||
| ); | ||
| }); | ||
|
|
||
| root.find(j.ObjectProperty, { key: { name: 'MuiDivider' } }).forEach((path) => { | ||
| const defaultPropsObject = path.value.value.properties.find( | ||
| (key) => key.key.name === 'defaultProps', | ||
| ); | ||
|
|
||
| defaultPropsObject.value.properties = defaultPropsObject.value.properties.filter( | ||
| (prop) => !['light'].includes(prop?.key?.name), | ||
| ); | ||
| }); | ||
|
|
||
| return root.toSource(printOptions); | ||
| } |
65 changes: 65 additions & 0 deletions
65
packages/mui-codemod/src/deprecations/divider-props/divider-props.test.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| import path from 'path'; | ||
| import { expect } from 'chai'; | ||
| import { jscodeshift } from '../../../testUtils'; | ||
| import transform from './divider-props'; | ||
| import readFile from '../../util/readFile'; | ||
|
|
||
| function read(fileName) { | ||
| return readFile(path.join(__dirname, fileName)); | ||
| } | ||
|
|
||
| describe('@mui/codemod', () => { | ||
| describe('deprecations', () => { | ||
| describe('divider-props', () => { | ||
| it('transforms props as needed', () => { | ||
| const actual = transform({ source: read('./test-cases/actual.js') }, { jscodeshift }, {}); | ||
|
|
||
| const expected = read('./test-cases/expected.js'); | ||
| expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
| }); | ||
|
|
||
| it('should be idempotent', () => { | ||
| const actual = transform({ source: read('./test-cases/expected.js') }, { jscodeshift }, {}); | ||
|
|
||
| const expected = read('./test-cases/expected.js'); | ||
| expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
| }); | ||
|
|
||
| it('actual.js should not be equal to expected.js', () => { | ||
| const actual = read('./test-cases/actual.js'); | ||
| const expected = read('./test-cases/expected.js'); | ||
| expect(actual).to.not.equal(expected); | ||
| }); | ||
| }); | ||
|
|
||
| describe('[theme] divider-props', () => { | ||
| it('transforms props as needed', () => { | ||
| const actual = transform( | ||
| { source: read('./test-cases/theme.actual.js') }, | ||
| { jscodeshift }, | ||
| {}, | ||
| ); | ||
|
|
||
| const expected = read('./test-cases/theme.expected.js'); | ||
| expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
| }); | ||
|
|
||
| it('should be idempotent', () => { | ||
| const actual = transform( | ||
| { source: read('./test-cases/theme.expected.js') }, | ||
| { jscodeshift }, | ||
| {}, | ||
| ); | ||
|
|
||
| const expected = read('./test-cases/theme.expected.js'); | ||
| expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
| }); | ||
|
|
||
| it('theme.actual.js should not be equal to theme.expected.js', () => { | ||
| const actual = read('./test-cases/theme.actual.js'); | ||
| const expected = read('./test-cases/theme.expected.js'); | ||
| expect(actual).to.not.equal(expected); | ||
| }); | ||
| }); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| export { default } from './divider-props'; |
9 changes: 9 additions & 0 deletions
9
packages/mui-codemod/src/deprecations/divider-props/test-cases/actual.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import Divider from '@mui/material/Divider'; | ||
| import { Divider as MyDivider } from '@mui/material'; | ||
|
|
||
| <Divider light />; | ||
| <MyDivider light />; | ||
| <Divider light={false} />; | ||
| <MyDivider light={false} />; | ||
| <Divider light={light} />; | ||
| <MyDivider light={light} />; |
9 changes: 9 additions & 0 deletions
9
packages/mui-codemod/src/deprecations/divider-props/test-cases/expected.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| import Divider from '@mui/material/Divider'; | ||
| import { Divider as MyDivider } from '@mui/material'; | ||
|
|
||
| <Divider />; | ||
| <MyDivider />; | ||
| <Divider />; | ||
| <MyDivider />; | ||
| <Divider />; | ||
| <MyDivider />; |
23 changes: 23 additions & 0 deletions
23
packages/mui-codemod/src/deprecations/divider-props/test-cases/theme.actual.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| fn({ | ||
| MuiDivider: { | ||
| defaultProps: { | ||
| light: true, | ||
| }, | ||
| }, | ||
| }); | ||
| fn({ | ||
| MuiDivider: { | ||
| defaultProps: { | ||
| light: true, | ||
| className: 'my-class', | ||
| }, | ||
| }, | ||
| }); | ||
| fn({ | ||
| MuiDivider: { | ||
| defaultProps: { | ||
| light, | ||
| className: 'my-class', | ||
| }, | ||
| }, | ||
| }); |
19 changes: 19 additions & 0 deletions
19
packages/mui-codemod/src/deprecations/divider-props/test-cases/theme.expected.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| fn({ | ||
| MuiDivider: { | ||
| defaultProps: {}, | ||
| }, | ||
| }); | ||
| fn({ | ||
| MuiDivider: { | ||
| defaultProps: { | ||
| className: 'my-class' | ||
| }, | ||
| }, | ||
| }); | ||
| fn({ | ||
| MuiDivider: { | ||
| defaultProps: { | ||
| className: 'my-class' | ||
| }, | ||
| }, | ||
| }); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.