https://github.com/codemodsquad/flow-codemorphs
general purpose codemods for flow
https://github.com/codemodsquad/flow-codemorphs
codemods flow jscodeshift
Last synced: 4 months ago
JSON representation
general purpose codemods for flow
- Host: GitHub
- URL: https://github.com/codemodsquad/flow-codemorphs
- Owner: codemodsquad
- License: mit
- Created: 2020-02-23T05:03:48.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-05T08:03:11.000Z (almost 3 years ago)
- Last Synced: 2025-05-28T03:50:27.141Z (4 months ago)
- Topics: codemods, flow, jscodeshift
- Language: TypeScript
- Size: 3.37 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 21
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# flow-codemorphs
[](https://circleci.com/gh/codemodsquad/flow-codemorphs)
[](https://codecov.io/gh/codemodsquad/flow-codemorphs)
[](https://github.com/semantic-release/semantic-release)
[](http://commitizen.github.io/cz-cli/)
[](https://badge.fury.io/js/flow-codemorphs)general purpose codemods for flow
# Table of Contents
- [makeExact](#makeexact)
- [makeInexact](#makeinexact)
- [makeReadOnly](#makereadonly)# makeExact
Converts object shape types to exact objects.
## Options
`ambiguousOnly` - if truthy, only ambiguous object shape types will be converted.
You can pass `selectionStart` and `selectionEnd` options to only convert types within that
range. If `selectionStart === selectionEnd`, only converts the type annotation containing
the cursor, unless no type annotation contains the cursor, in which case it converts
everything.## Example
### Before
```ts
// @flow
type Foo = {
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{
blsdf: string,
}>,
glorb: {a: number}[],
...
}>,
}```
### Command
```
jscodeshift -t path/to/flow-codemorphs/makeExact.js
```### After
```ts
// @flow
type Foo = {|
bar: number,
baz: Array<{|
qux: number,
blah: $ReadOnly<{| blsdf: string |}>,
glorb: {| a: number |}[],
|}>,
|}```
# makeInexact
Converts object shape types to inexact objects.
## Options
`ambiguousOnly` - if truthy, only ambiguous object shape types will be converted.
You can pass `selectionStart` and `selectionEnd` options to only convert types within that
range. If `selectionStart === selectionEnd`, only converts the type annotation containing
the cursor, unless no type annotation contains the cursor, in which case it converts
everything.## Example
### Before
```ts
// @flow
type Foo = {|
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{|
blsdf: string,
|}>,
glorb: {a: number}[],
...
}>,
|}```
### Command
```
jscodeshift -t path/to/flow-codemorphs/makeInexact.js
```### After
```ts
// @flow
type Foo = {
bar: number,
baz: Array<{
qux: number,
blah: $ReadOnly<{ blsdf: string, ... }>,
glorb: { a: number, ... }[],
...
}>,
...
}```
# makeReadOnly
Converts mutable object shape and array types to readonly types.
## Options
You can pass `selectionStart` and `selectionEnd` options to only convert types within that
range. If `selectionStart === selectionEnd`, only converts the type annotation containing
the cursor, unless no type annotation contains the cursor, in which case it converts
everything.## Example
### Before
```ts
// @flowtype Foo = {
bar: number
baz: Array<{
qux: number
blah: $ReadOnly<{
blsdf: string
}>
glorb: { a: number }[]
}>
}
```### Command
```
jscodeshift -t path/to/flow-codemorphs/makeReadOnly.js
```### After
```ts
// @flowtype Foo = $ReadOnly<{
bar: number
baz: $ReadOnlyArray<
$ReadOnly<{
qux: number
blah: $ReadOnly<{
blsdf: string
}>
glorb: $ReadOnlyArray<$ReadOnly<{ a: number }>>
}>
>
}>
```