https://github.com/vscodeshift/flow-codemorphs
general purpose codemods for flow
https://github.com/vscodeshift/flow-codemorphs
codemods flow flowtype jscodeshift refactoring
Last synced: 6 months ago
JSON representation
general purpose codemods for flow
- Host: GitHub
- URL: https://github.com/vscodeshift/flow-codemorphs
- Owner: vscodeshift
- License: mit
- Created: 2020-02-27T03:11:13.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T08:25:51.000Z (almost 3 years ago)
- Last Synced: 2025-02-10T09:15:15.911Z (8 months ago)
- Topics: codemods, flow, flowtype, jscodeshift, refactoring
- Language: TypeScript
- Size: 3.85 MB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 22
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# @vscodeshift/flow-codemorphs
[](https://circleci.com/gh/vscodeshift/flow-codemorphs)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
[](https://marketplace.visualstudio.com/items?itemName=vscodeshift.flow-codemorphs)general purpose codemods for flow
# Commands
- [make exact](#make-exact)
- [make inexact](#make-inexact)
- [make read-only](#make-read-only)# make exact
Converts object shape types to exact objects.
If you position the cursor inside a type annotation, only objects within that
type annotation are converted.If there is a selection, only objects within the selection are converted.
## Example
### Before
```ts
// @flow
type Foo = {
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{
blsdf: string,
}>,
glorb: {a: number}[],
...
}>,
}```
### After
```ts
// @flow
type Foo = {|
bar: number,
baz: Array<{|
qux: number,
blah: $ReadOnly<{| blsdf: string |}>,
glorb: {| a: number |}[],
|}>,
|}```
# make inexact
Converts object shape types to inexact objects.
If you position the cursor inside a type annotation, only objects within that
type annotation are converted.If there is a selection, only objects within the selection are converted.
## Example
### Before
```ts
// @flow
type Foo = {|
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{|
blsdf: string,
|}>,
glorb: {a: number}[],
...
}>,
|}```
### After
```ts
// @flow
type Foo = {
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{ blsdf: string, ... }>,
glorb: { a: number, ... }[],
...
}>,
...
}```
# make read-only
Converts mutable object shape and array types to readonly types.
If you position the cursor inside a type annotation, only objects
and arrays within that type annotation are converted.If there is a selection, only objects and arrays within the selection are converted.
## Example
### Before
```ts
// @flowtype Foo = {
bar: number
baz: Array<{
qux: number
blah: $ReadOnly<{
blsdf: string
}>
glorb: { a: number }[]
}>
}
```### After
```ts
// @flowtype Foo = $ReadOnly<{
bar: number
baz: $ReadOnlyArray<
$ReadOnly<{
qux: number
blah: $ReadOnly<{
blsdf: string
}>
glorb: $ReadOnlyArray<$ReadOnly<{ a: number }>>
}>
>
}>
```