Skip to content

Commit 6dcd169

Browse files
committed
📚 Minor doc changes
1 parent 3377c69 commit 6dcd169

File tree

4 files changed

+45
-16
lines changed

4 files changed

+45
-16
lines changed

website/docs/ecosystem.mdx

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,20 @@ The ecosystem is full of amazing resources and examples, please check them out.
1414
## Tools
1515

1616
- [jscodeshift](https://github.com/facebook/jscodeshift)
17-
- [astexplorer.net/](https://astexplorer.net/)
17+
- [astexplorer.net](https://astexplorer.net/)
1818
- [recast](https://github.com/benjamn/recast)
1919

20+
## Blogs & Guides
21+
22+
- [Writing your very first codemod with jscodeshift](https://medium.com/@andrew_levine/writing-your-very-first-codemod-with-jscodeshift-7a24c4ede31b)
23+
- [Automatic refactoring with codemods](https://itnext.io/automatic-refactoring-with-jscodeshift-codemods-45c219eaf992)
24+
- [Getting Started with Codemods](https://www.sitepoint.com/getting-started-with-codemods/)
25+
- [Codemods: Effective, Automated Refactoring](https://www.sitepen.com/blog/codemods-effective-automated-refactoring)
26+
- [Creating a custom transform for jscodeshift](https://skovy.dev/jscodeshift-custom-transform/)
27+
- [Building AST nodes from source code](https://dev.to/rajasegar/building-ast-nodes-from-source-code-3p49)
28+
- [How to write a codemod](https://vramana.github.io/blog/2015/12/21/codemod-tutorial/)
29+
- [Writing Javascript Codemods and Understanding AST Easily](https://katilius.dev/writing-js-codemods/)
30+
2031
## People
2132

2233
Original authors of [jscodeshift](https://github.com/facebook/jscodeshift)
@@ -42,16 +53,6 @@ Creator of [recast](https://github.com/benjamn/recast)
4253
- [date-fns](https://github.com/date-fns/date-fns-upgrade-codemod)
4354
- [react-hook-form](https://github.com/react-hook-form/codemod)
4455

45-
## Blogs & Guides
46-
47-
- [Writing your very first codemod with jscodeshift](https://medium.com/@andrew_levine/writing-your-very-first-codemod-with-jscodeshift-7a24c4ede31b)
48-
- [Automatic refactoring with codemods](https://itnext.io/automatic-refactoring-with-jscodeshift-codemods-45c219eaf992)
49-
- [Getting Started with Codemods](https://www.sitepoint.com/getting-started-with-codemods/)
50-
- [Codemods: Effective, Automated Refactoring](https://www.sitepen.com/blog/codemods-effective-automated-refactoring)
51-
- [Creating a custom transform for jscodeshift](https://skovy.dev/jscodeshift-custom-transform/)
52-
- [Building AST nodes from source code](https://dev.to/rajasegar/building-ast-nodes-from-source-code-3p49)
53-
- [How to write a codemod](https://vramana.github.io/blog/2015/12/21/codemod-tutorial/)
54-
5556
## Misc
5657

5758
- [facebook-codemod](https://github.com/facebook/codemod)

website/docs/glossary.mdx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,18 @@ slug: /glossary
1010
1111
[Reference](https://medium.com/@andrew_levine/writing-your-very-first-codemod-with-jscodeshift-7a24c4ede31b)
1212

13+
## Transform
14+
15+
A transform is simply a javascript function which serves as the entry-point for your codemod.
16+
17+
For example:
18+
19+
```jsx
20+
export default function transform(file, { jscodeshift: j }, options) {
21+
//... codemod goes here
22+
}
23+
```
24+
1325
## Motion
1426

1527
A motion (aka migration) is what we call specific actions performed within a codemod. Put simply, javascript functions that are responsible for a single action within a codemod.
@@ -26,6 +38,10 @@ For more information see: [Authoring](/docs/authoring#motions)
2638

2739
[jscodeshift](https://github.com/facebook/jscodeshift) is the underlying library used by CodeshiftCommunity.
2840

41+
- Provides both a CLI for running transforms and a jQuery-like API for manipulating ASTs
42+
- AST transformations are performed using a wrapper around [recast](https://github.com/benjamn/recast).
43+
- The AST is implemented in [ast-types](https://github.com/benjamn/ast-types), which is itself based on [esprima](https://esprima.org/)
44+
2945
## recast
3046

3147
[recast](https://github.com/benjamn/recast) is the underlying library used by jscodeshift to parse, transform and output files as ASTs. It's a comparable library to [babel](https://babeljs.io/)
@@ -36,6 +52,8 @@ For more information see: [Authoring](/docs/authoring#motions)
3652

3753
## ast-types
3854

55+
[ast-types](https://github.com/benjamn/ast-types)
56+
3957
> Another great library authored by Ben Newman. It exposes 2 kinds of helpers that you’ll be using: functions that allow you to verify assumptions about nodes, and functions that allow you to compose new nodes to be added to an existing AST.
4058
4159
[Reference](https://medium.com/@andrew_levine/writing-your-very-first-codemod-with-jscodeshift-7a24c4ede31b)

website/docs/guides/when-not-to-codemod.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ const App = props => {
8989

9090
## What to do when a codemod isn't possible?
9191

92-
### Prompting for user input
92+
### Prompt for user input
9393

9494
In most cases, we recommend that you aim to do as much of the work as possible, right up until you can't reasonably to anymore. Then prompt users for their intervention.
9595

website/docs/guiding-principles.mdx

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,25 @@ There are several guiding principles we follow in this project.
88

99
## Codemods should target a version of package
1010

11-
Code is always on the move and codemods written against a specific API, at a specific point of time aren't guaranteed to work in the future.
12-
We believe codemods should only aim to migrate from one API to another, by limiting the scope of change to a specific package and version.
13-
In doing so the scope and intent of a codemod is encoded and always obvious to users.
11+
Code is always on the move and codemods written against a specific API, at a specific point of time aren't guaranteed to work into the future.
12+
That's why we should aim to limit the scope of a codemod to migrate a specific package from one API to another.
13+
14+
In doing so:
15+
16+
- The scope and intent of a codemod is encoded and always obvious to users.
17+
- Changes to the package that occur thereafter should not affect or break older codemods.
18+
- Allow us to go back and patch older codemods if necessary.
19+
20+
Conversely, if codemods were named arbitrarily, there will be no apparent sequence for the consumer to follow.
1421

1522
## Codemods should be playable in sequence
1623

17-
By writing codemods that target a package and version, it should then be possible to move consumers across major versions by playing them in a sequence.
24+
By writing codemods that target a package and version, it should then be theoretically possible to move your consumers across multiple major versions by playing them in a sequence.
1825
For example, migrating from an older version of `@mylib/button` to the latest is possible by playing all available codemods in order `v14 -> v15 -> v16`.
1926

27+
Ultimately, this is the happy-path this project strives for. But it's also important to meantion that in reality this might not always be possible depending on how your package might be consumed and how hard it might be to write a codemods for it.
28+
In these cases we recommend that you are aware of [when not to codemod](/docs/when-not-to-codemod) and [what to do when a codemod isn't possible](/docs/when-not-to-codemod#what-to-do-when-a-codemod-isnt-possible)
29+
2030
## Codemods should do as much as can be safely done, automatically and prompt for human intervention when needed
2131

2232
Writing a codemod to completely migrate a package from one working state to another is not always feasible. Some edgecases might simply be too hard to support.

0 commit comments

Comments
 (0)