flow-codemorphs

1.0.2 • Public • Published

flow-codemorphs

CircleCI Coverage Status semantic-release Commitizen friendly npm version

general purpose codemods for flow

Table of Contents

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

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

After

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

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

After

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

// @flow

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

Command

jscodeshift -t path/to/flow-codemorphs/makeReadOnly.js <file>

After

// @flow

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

Dependents (0)

Package Sidebar

Install

npm i flow-codemorphs

Weekly Downloads

0

Version

1.0.2

License

MIT

Unpacked Size

426 kB

Total Files

19

Last publish

Collaborators

  • jedwards1211