Flow Formatter

Format and beautify Flow code.

Local Your input is processed locally in your browser. The first run loads the open-source Prettier library from this site; your input is not sent anywhere. Found a problem? Report an issue

What the Flow Formatter does

The Flow Formatter formats JavaScript with Flow type annotations with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports JavaScript with Flow annotations; the // @flow pragma is kept.

Flow Formatter examples

The built-in sample

Input

// @flow
type User={|id:number,name?:string|};
const label=(u:User):?string=>u.name

Output

// @flow
type User = {| id: number, name?: string |};
const label = (u: User): ?string => u.name;

This is the input that the Load sample button fills in.

Interfaces and Flow enums

Input

interface A { x: number }
enum E {A, B}

Output

interface A {
  x: number;
}
enum E {
  A,
  B,
}

Members are put on their own lines with semicolons or commas, as Prettier does for Flow declarations.

Each output was produced by running this tool on the input above it.

How it works

The code is parsed with Prettier's babel-flow parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out. If the code cannot be parsed, the parser's message with its line and column is shown instead of output.

Details and limits

  • The // @flow comment is kept but not required: the Flow parser is used whatever the first line says.
  • Exact object types ({| |}), maybe types (?string) and type imports are all supported.
  • TypeScript-only syntax, such as namespace blocks, constructor parameter properties or the ! non-null assertion, is a syntax error here. Use the TypeScript Formatter.

Questions

Is my data uploaded when I use Flow Formatter?

No. The tool runs in your browser, so what you paste or open is processed on your own device and is not sent to a server.

What does Flow Formatter do?

The Flow Formatter formats JavaScript with Flow type annotations with Prettier 3.3.3, an open-source code formatter, running in your browser. It supports JavaScript with Flow annotations; the // @flow pragma is kept.

How does Flow Formatter work?

The code is parsed with Prettier's babel-flow parser and printed again from its syntax tree, using Prettier's default options: lines up to 80 characters and two-space indentation. The result therefore does not depend on how the input was laid out.

Are there any limits I should know about?

The // @flow comment is kept but not required: the Flow parser is used whatever the first line says. Exact object types ({| |}), maybe types (?string) and type imports are all supported.

Is there a size limit?

There is no fixed size limit. Everything happens on your device, so very large inputs depend on its memory and can take longer on a phone than on a computer.

Does it work on phones, and is it free?

Yes. It works in any current browser on Android phones, iPhones, tablets and computers. It is free and needs no account or sign-up.