forked from mui/mui-x
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[codemod] Add codemod to use
referenceDate
instead of `defaultCalen…
…darMonth` (mui#11139)
- Loading branch information
1 parent
037d1ef
commit a022c67
Showing
7 changed files
with
106 additions
and
5 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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 |
---|---|---|
@@ -1,9 +1,11 @@ | ||
import transformRenameComponentsToSlots from '../../../v6.0.0/pickers/rename-components-to-slots'; | ||
import transformRenameDefaultCalendarMonthToReferenceDate from '../rename-default-calendar-month-to-reference-date'; | ||
|
||
import { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; | ||
|
||
export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { | ||
file.source = transformRenameComponentsToSlots(file, api, options); | ||
file.source = transformRenameDefaultCalendarMonthToReferenceDate(file, api, options); | ||
|
||
return file.source; | ||
} |
16 changes: 16 additions & 0 deletions
16
...codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/actual.spec.js
This file contains 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,16 @@ | ||
<> | ||
<DateCalendar defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<DatePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<DateRangeCalendar defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<DateRangePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<DateTimePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<DesktopDatePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<DesktopDateRangePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<DesktopDateTimePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<MobileDatePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<MobileDateRangePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<MobileDateTimePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<StaticDatePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<StaticDateRangePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
<StaticDateTimePicker defaultCalendarMonth={dayjs('2022-04-01')} /> | ||
</>; |
16 changes: 16 additions & 0 deletions
16
...demod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/expected.spec.js
This file contains 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,16 @@ | ||
<> | ||
<DateCalendar referenceDate={dayjs('2022-04-01')} /> | ||
<DatePicker referenceDate={dayjs('2022-04-01')} /> | ||
<DateRangeCalendar referenceDate={dayjs('2022-04-01')} /> | ||
<DateRangePicker referenceDate={dayjs('2022-04-01')} /> | ||
<DateTimePicker referenceDate={dayjs('2022-04-01')} /> | ||
<DesktopDatePicker referenceDate={dayjs('2022-04-01')} /> | ||
<DesktopDateRangePicker referenceDate={dayjs('2022-04-01')} /> | ||
<DesktopDateTimePicker referenceDate={dayjs('2022-04-01')} /> | ||
<MobileDatePicker referenceDate={dayjs('2022-04-01')} /> | ||
<MobileDateRangePicker referenceDate={dayjs('2022-04-01')} /> | ||
<MobileDateTimePicker referenceDate={dayjs('2022-04-01')} /> | ||
<StaticDatePicker referenceDate={dayjs('2022-04-01')} /> | ||
<StaticDateRangePicker referenceDate={dayjs('2022-04-01')} /> | ||
<StaticDateTimePicker referenceDate={dayjs('2022-04-01')} /> | ||
</>; |
31 changes: 31 additions & 0 deletions
31
...ges/x-codemod/src/v7.0.0/pickers/rename-default-calendar-month-to-reference-date/index.ts
This file contains 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,31 @@ | ||
import renameProps from '../../../util/renameProps'; | ||
import type { JsCodeShiftAPI, JsCodeShiftFileInfo } from '../../../types'; | ||
|
||
export default function transformer(file: JsCodeShiftFileInfo, api: JsCodeShiftAPI, options: any) { | ||
const j = api.jscodeshift; | ||
const root = j(file.source); | ||
|
||
const printOptions = options.printOptions; | ||
|
||
return renameProps({ | ||
root, | ||
componentNames: [ | ||
'DateCalendar', | ||
'DatePicker', | ||
'DateRangeCalendar', | ||
'DateRangePicker', | ||
'DateTimePicker', | ||
'DesktopDatePicker', | ||
'DesktopDateRangePicker', | ||
'DesktopDateTimePicker', | ||
'MobileDatePicker', | ||
'MobileDateRangePicker', | ||
'MobileDateTimePicker', | ||
'StaticDatePicker', | ||
'StaticDateRangePicker', | ||
'StaticDateTimePicker', | ||
], | ||
props: { defaultCalendarMonth: 'referenceDate' }, | ||
j, | ||
}).toSource(printOptions); | ||
} |
27 changes: 27 additions & 0 deletions
27
...-calendar-month-to-reference-date/rename-default-calendar-month-to-reference-date.test.ts
This file contains 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,27 @@ | ||
import path from 'path'; | ||
import { expect } from 'chai'; | ||
import jscodeshift from 'jscodeshift'; | ||
import transform from '.'; | ||
import readFile from '../../../util/readFile'; | ||
|
||
function read(fileName) { | ||
return readFile(path.join(__dirname, fileName)); | ||
} | ||
|
||
describe('v7.0.0/pickers', () => { | ||
describe('rename-default-calendar-month-to-reference-date', () => { | ||
it('transforms props as needed', () => { | ||
const actual = transform({ source: read('./actual.spec.js') }, { jscodeshift }, {}); | ||
|
||
const expected = read('./expected.spec.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
|
||
it('should be idempotent', () => { | ||
const actual = transform({ source: read('./expected.spec.js') }, { jscodeshift }, {}); | ||
|
||
const expected = read('./expected.spec.js'); | ||
expect(actual).to.equal(expected, 'The transformed version should be correct'); | ||
}); | ||
}); | ||
}); |