-
Notifications
You must be signed in to change notification settings - Fork 186
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(Select, CustomSelect, NativeSelect): add codemods
- Loading branch information
1 parent
9cd1b75
commit e871f60
Showing
4 changed files
with
41 additions
and
0 deletions.
There are no files selected for viewing
16 changes: 16 additions & 0 deletions
16
packages/codemods/src/transforms/v7/common/warnSelectOnChange.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,16 @@ | ||
import { API, Collection } from 'jscodeshift'; | ||
import { report } from '../../../report'; | ||
|
||
export const warnSelectOnChange = (api: API, source: Collection, componentName: string) => { | ||
const j = api.jscodeshift; | ||
source | ||
.find(j.JSXOpeningElement, { name: { name: componentName } }) | ||
.find(j.JSXAttribute) | ||
.filter((attr) => attr.node.name.name === 'onChange') | ||
.forEach(() => { | ||
report( | ||
api, | ||
`Manual changes required for ${componentName}'s "onChange" prop: need to change event argument to select value`, | ||
); | ||
}); | ||
}; |
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 |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { API, FileInfo } from 'jscodeshift'; | ||
import { getImportInfo } from '../../codemod-helpers'; | ||
import { JSCodeShiftOptions } from '../../types'; | ||
import { warnSelectOnChange } from './common/warnSelectOnChange'; | ||
|
||
export const parser = 'tsx'; | ||
|
||
export default function transformer(file: FileInfo, api: API, options: JSCodeShiftOptions) { | ||
const { alias } = options; | ||
const j = api.jscodeshift; | ||
const source = j(file.source); | ||
const { localName } = getImportInfo(j, file, 'NativeSelect', alias); | ||
|
||
if (!localName) { | ||
return source.toSource(); | ||
} | ||
|
||
warnSelectOnChange(api, source, localName); | ||
|
||
return source.toSource(); | ||
} |
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