Skip to content

vscodeshift/flow-codemorphs

Repository files navigation

@vscodeshift/flow-codemorphs

CircleCI semantic-release Commitizen friendly Visual Studio Marketplace Version

general purpose codemods for flow

Commands

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

// @flow

type Foo = {
  bar: number,
  baz: Array<{
    qux: number,
    blah: $ReadOnly<{
      blsdf: string,
    }>,
    glorb: {a: number}[],
    ...
  }>,
}

After

// @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

// @flow

type Foo = {|
  bar: number,
  baz: Array<{
    qux: number,
    blah: $ReadOnly<{|
      blsdf: string,
    |}>,
    glorb: {a: number}[],
    ...
  }>,
|}

After

// @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

// @flow

type Foo = {
  bar: number
  baz: Array<{
    qux: number
    blah: $ReadOnly<{
      blsdf: string
    }>
    glorb: { a: number }[]
  }>
}

After

// @flow

type Foo = $ReadOnly<{
  bar: number
  baz: $ReadOnlyArray<
    $ReadOnly<{
      qux: number
      blah: $ReadOnly<{
        blsdf: string
      }>
      glorb: $ReadOnlyArray<$ReadOnly<{ a: number }>>
    }>
  >
}>