-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Makes validateWith async and a new validateWithSync synchronous (#7681)
* Adds new validateWithSync function * add codemod * Adds tests * Adds docs for validateWith() * fix yarn check --------- Co-authored-by: Dominic Saadi <dominiceliassaadi@gmail.com>
- Loading branch information
Showing
9 changed files
with
151 additions
and
13 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
4 changes: 4 additions & 0 deletions
4
packages/codemods/src/codemods/v5.x.x/renameValidateWith/README.md
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,4 @@ | ||
# Rename `validateWith` | ||
|
||
For (https://github.com/redwoodjs/redwood/pull/7681)[https://github.com/redwoodjs/redwood/pull/7681]. | ||
This codemod renames any instance of `validateWith` to `validateWithSync`. |
11 changes: 11 additions & 0 deletions
11
packages/codemods/src/codemods/v5.x.x/renameValidateWith/__testfixtures__/default.input.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,11 @@ | ||
validateWith(() => { | ||
if (input.name === 'Name') { | ||
throw "You'll have to be more creative than that" | ||
} | ||
}) | ||
|
||
validateWith(() => { | ||
if (input.name === 'Name') { | ||
throw new Error("You'll have to be more creative than that") | ||
} | ||
}) |
11 changes: 11 additions & 0 deletions
11
packages/codemods/src/codemods/v5.x.x/renameValidateWith/__testfixtures__/default.output.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,11 @@ | ||
validateWithSync(() => { | ||
if (input.name === 'Name') { | ||
throw "You'll have to be more creative than that" | ||
} | ||
}) | ||
|
||
validateWithSync(() => { | ||
if (input.name === 'Name') { | ||
throw new Error("You'll have to be more creative than that") | ||
} | ||
}) |
5 changes: 5 additions & 0 deletions
5
...ages/codemods/src/codemods/v5.x.x/renameValidateWith/__tests__/renameValidateWith.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,5 @@ | ||
describe('renameValidateWith', () => { | ||
it('Converts validateWith to validateWithSync', async () => { | ||
await matchTransformSnapshot('renameValidateWith', 'default') | ||
}) | ||
}) |
15 changes: 15 additions & 0 deletions
15
packages/codemods/src/codemods/v5.x.x/renameValidateWith/renameValidateWith.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,15 @@ | ||
import type { FileInfo, API } from 'jscodeshift' | ||
|
||
export default function transform(file: FileInfo, api: API) { | ||
const j = api.jscodeshift | ||
const root = j(file.source) | ||
|
||
root | ||
.find(j.Identifier, { | ||
type: 'Identifier', | ||
name: 'validateWith', | ||
}) | ||
.replaceWith({ type: 'Identifier', name: 'validateWithSync' }) | ||
|
||
return root.toSource() | ||
} |
29 changes: 29 additions & 0 deletions
29
packages/codemods/src/codemods/v5.x.x/renameValidateWith/renameValidateWith.yargs.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,29 @@ | ||
import path from 'path' | ||
|
||
import task, { TaskInnerAPI } from 'tasuku' | ||
|
||
import getFilesWithPattern from '../../../lib/getFilesWithPattern' | ||
import getRWPaths from '../../../lib/getRWPaths' | ||
import runTransform from '../../../lib/runTransform' | ||
|
||
export const command = 'rename-validate-with' | ||
export const description = | ||
'(v4.x.x->v5.x.x) Converts validateWith to validateWithSync' | ||
|
||
export const handler = () => { | ||
task('Rename Validate With', async ({ setOutput }: TaskInnerAPI) => { | ||
const rwPaths = getRWPaths() | ||
|
||
const files = getFilesWithPattern({ | ||
pattern: 'validateWith', | ||
filesToSearch: [rwPaths.api.src], | ||
}) | ||
|
||
await runTransform({ | ||
transformPath: path.join(__dirname, 'renameValidateWith.js'), | ||
targetPaths: files, | ||
}) | ||
|
||
setOutput('All done! Run `yarn rw lint --fix` to prettify your code') | ||
}) | ||
} |