https://github.com/valerybugakov/codemods
https://github.com/valerybugakov/codemods
Last synced: about 1 year ago
JSON representation
- Host: GitHub
- URL: https://github.com/valerybugakov/codemods
- Owner: valerybugakov
- Created: 2019-10-30T18:02:22.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-01-04T23:47:27.000Z (over 3 years ago)
- Last Synced: 2025-02-10T08:32:29.224Z (over 1 year ago)
- Language: JavaScript
- Size: 197 KB
- Stars: 2
- Watchers: 0
- Forks: 0
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# JS codemods
Preview code AST of the target code using [AST explorer](https://astexplorer.net/).
To interactively test and update codemods might be helpful to use [ndb](https://github.com/GoogleChromeLabs/ndb).
```sh
ndb npx jscodeshift -t ./transforms/something.js --extensions=ts --parser=tsx ./src/**/*container.ts
```
## Usage
1. `yarn`
2. `npx jscodeshift -t ./transforms/[transform].js [files]`
3. Review changes via `git diff`. Keep what you want, throw it out if you don't. Magic!
## Option flags
When executing codemods, you can configure options like so:
`npx jscodeshift -t node_modules/5to6-codemod/transforms/[transform].js [files] --key=value`
### Recast options
Transforms will automatically distinguish and pass through Recast config keys via [jscodeshift](https://github.com/facebook/jscodeshift#passing-options-to-recast). Official documentation for Recast's configuration can be found [here](https://github.com/benjamn/recast/blob/4899a70d4b9aeec9c599065be3338464b7047767/lib/options.js#L1). The following Recast keys are supported:
- `esprima`
- `inputSourceMap`
- `lineTerminator`
- `quote`
- `range`
- `reuseWhitespace`
- `sourceFileName`
- `sourceMapName`
- `sourceRoot`
- `tabWidth`
- `tolerant`
- `trailingComma`
- `useTabs`
- `wrapColumn`
## Known issues
Some TS features might not work because latest release of jscodeshift is not yet published to NPM.
https://github.com/facebook/jscodeshift/issues/330