Skip to content

Commit 280fc68

Browse files
Merge pull request #15 from danielo515/patch-1
2 parents 148cd7f + 6fbf34a commit 280fc68

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

website/docs/guides/your-first-codemod.mdx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export default function transform(file, { jscodeshift: j }, options) {
4747
}
4848
```
4949

50+
If you prefer a more declarative approach, you can provide a second argument to `find` describing the expected shape of the node you are looking for.
51+
52+
```ts
53+
const imports = source
54+
.find(j.ImportDeclaration, { source: { value: 'my-module' } }) // Find all import declarations that match this shape
55+
```
56+
57+
This behaves like a fuzzy searcher: The more details provided the more narrow the search is.
58+
5059
## Modify & Insert
5160

5261
Now let's say that we want to pull in a new import from 'my-module' called `baz`. Luckily you've already written a majority of the code above.

0 commit comments

Comments
 (0)