Skip to content

Commit a73cdf2

Browse files
committed
Updates
0 parents  commit a73cdf2

769 files changed

Lines changed: 105066 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

404.html

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<!doctype html>
2+
<html lang="en" dir="ltr" class="plugin-native plugin-id-default" data-has-hydrated="false">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="generator" content="Docusaurus v3.7.0">
6+
<title data-rh="true">Page Not Found | Flow</title><meta data-rh="true" name="viewport" content="width=device-width,initial-scale=1"><meta data-rh="true" name="twitter:card" content="summary_large_image"><meta data-rh="true" property="og:url" content="https://flow.org/404.html/"><meta data-rh="true" property="og:locale" content="en"><meta data-rh="true" name="docusaurus_locale" content="en"><meta data-rh="true" name="docusaurus_tag" content="default"><meta data-rh="true" name="docsearch:language" content="en"><meta data-rh="true" name="docsearch:docusaurus_tag" content="default"><meta data-rh="true" property="og:title" content="Page Not Found | Flow"><link data-rh="true" rel="icon" href="/img/favicon.png"><link data-rh="true" rel="canonical" href="https://flow.org/404.html/"><link data-rh="true" rel="alternate" href="https://flow.org/404.html/" hreflang="en"><link data-rh="true" rel="alternate" href="https://flow.org/404.html/" hreflang="x-default"><link data-rh="true" rel="preconnect" href="https://P6T3E8XPGT-dsn.algolia.net" crossorigin="anonymous"><link rel="alternate" type="application/rss+xml" href="/blog/rss.xml" title="Flow RSS Feed">
7+
<link rel="alternate" type="application/atom+xml" href="/blog/atom.xml" title="Flow Atom Feed">
8+
9+
<link rel="preconnect" href="https://www.google-analytics.com">
10+
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","UA-49208336-4","auto"),ga("set","anonymizeIp",!0),ga("send","pageview")</script>
11+
<script async src="https://www.google-analytics.com/analytics.js"></script>
12+
13+
14+
15+
<link rel="search" type="application/opensearchdescription+xml" title="Flow" href="/opensearch.xml"><link rel="stylesheet" href="/assets/css/styles.87fc1c6a.css">
16+
<script src="/assets/js/runtime~main.2bf66f43.js" defer="defer"></script>
17+
<script src="/assets/js/main.0ba02678.js" defer="defer"></script>
18+
</head>
19+
<body class="navigation-with-keyboard">
20+
<script>!function(){function t(t){document.documentElement.setAttribute("data-theme",t)}var e=function(){try{return new URLSearchParams(window.location.search).get("docusaurus-theme")}catch(t){}}()||function(){try{return window.localStorage.getItem("theme")}catch(t){}}();t(null!==e?e:"light")}(),function(){try{const n=new URLSearchParams(window.location.search).entries();for(var[t,e]of n)if(t.startsWith("docusaurus-data-")){var a=t.replace("docusaurus-data-","data-");document.documentElement.setAttribute(a,e)}}catch(t){}}()</script>
21+
22+
<div style="display: none; text-align: center; background-color: white; color: black;" id="internaldocs-banner"></div><div id="__docusaurus"><div role="region" aria-label="Skip to main content"><a class="skipToContent_fXgn" href="#__docusaurus_skipToContent_fallback">Skip to main content</a></div><nav aria-label="Main" class="navbar navbar--fixed-top"><div class="navbar__inner"><div class="navbar__items"><button aria-label="Toggle navigation bar" aria-expanded="false" class="navbar__toggle clean-btn" type="button"><svg width="30" height="30" viewBox="0 0 30 30" aria-hidden="true"><path stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="2" d="M4 7h22M4 15h22M4 23h22"></path></svg></button><a class="navbar__brand" href="/"><div class="navbar__logo"><img src="/img/logo.svg" alt="My Facebook Project Logo" class="themedComponent_mlkZ themedComponent--light_NVdE"><img src="/img/logo.svg" alt="My Facebook Project Logo" class="themedComponent_mlkZ themedComponent--dark_xIcU"></div></a><a class="navbar__item navbar__link" href="/en/docs/getting-started/">Getting Started</a><a class="navbar__item navbar__link" href="/en/docs/">Docs</a><a class="navbar__item navbar__link" href="/try/">Try</a><a class="navbar__item navbar__link" href="/blog/">Blog</a></div><div class="navbar__items navbar__items--right"><a href="https://twitter.com/flowtype" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar__icon twitter__link" aria-label="Twitter"></a><a href="http://stackoverflow.com/questions/tagged/flowtype" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar__icon stackoverflow__link" aria-label="Stack Overflow"></a><a href="https://github.com/facebook/flow" target="_blank" rel="noopener noreferrer" class="navbar__item navbar__link navbar__icon github__link" aria-label="GitHub"></a><div class="navbarSearchContainer_Bca1"><button type="button" class="DocSearch DocSearch-Button" aria-label="Search (Command+K)"><span class="DocSearch-Button-Container"><svg width="20" height="20" class="DocSearch-Search-Icon" viewBox="0 0 20 20" aria-hidden="true"><path d="M14.386 14.386l4.0877 4.0877-4.0877-4.0877c-2.9418 2.9419-7.7115 2.9419-10.6533 0-2.9419-2.9418-2.9419-7.7115 0-10.6533 2.9418-2.9419 7.7115-2.9419 10.6533 0 2.9419 2.9418 2.9419 7.7115 0 10.6533z" stroke="currentColor" fill="none" fill-rule="evenodd" stroke-linecap="round" stroke-linejoin="round"></path></svg><span class="DocSearch-Button-Placeholder">Search</span></span><span class="DocSearch-Button-Keys"></span></button></div></div></div><div role="presentation" class="navbar-sidebar__backdrop"></div></nav><div id="__docusaurus_skipToContent_fallback" class="main-wrapper mainWrapper_z2l0"><main class="container margin-vert--xl"><div class="row"><div class="col col--6 col--offset-3"><h1 class="hero__title">Page Not Found</h1><p>We could not find what you were looking for.</p><p>Please contact the owner of the site that linked you to the original URL and let them know their link is broken.</p></div></div></main></div><footer class="footer footer--dark"><div class="container container-fluid"><div class="row footer__links"><div class="col footer__col"><div class="footer__title">Learn</div><ul class="footer__items clean-list"><li class="footer__item"><a class="footer__link-item" href="/en/docs/getting-started/">Getting Started</a></li></ul></div><div class="col footer__col"><div class="footer__title">Community</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://twitter.com/flowtype" target="_blank" rel="noopener noreferrer" class="footer__link-item">Twitter<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://discordapp.com/invite/8ezwRUK" target="_blank" rel="noopener noreferrer" class="footer__link-item">Discord<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">More</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://medium.com/flow-type" target="_blank" rel="noopener noreferrer" class="footer__link-item">Medium</a></li><li class="footer__item"><a href="https://github.com/facebook/flow" target="_blank" rel="noopener noreferrer" class="footer__link-item">GitHub<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div><div class="col footer__col"><div class="footer__title">Legal</div><ul class="footer__items clean-list"><li class="footer__item"><a href="https://opensource.facebook.com/legal/privacy/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Privacy<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/terms/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Terms<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/data-policy/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Data Policy<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li><li class="footer__item"><a href="https://opensource.facebook.com/legal/cookie-policy/" target="_blank" rel="noopener noreferrer" class="footer__link-item">Cookie Policy<svg width="13.5" height="13.5" aria-hidden="true" viewBox="0 0 24 24" class="iconExternalLink_nPIU"><path fill="currentColor" d="M21 13v10h-21v-19h12v2h-10v15h17v-8h2zm3-12h-10.988l4.035 4-6.977 7.07 2.828 2.828 6.977-7.07 4.125 4.172v-11z"></path></svg></a></li></ul></div></div><div class="footer__bottom text--center"><div class="margin-bottom--sm"><a href="https://opensource.facebook.com" rel="noopener noreferrer" class="footerLogoLink_BH7S"><img src="/img/oss_logo.png" alt="Facebook Open Source Logo" class="footer__logo themedComponent_mlkZ themedComponent--light_NVdE"><img src="/img/oss_logo.png" alt="Facebook Open Source Logo" class="footer__logo themedComponent_mlkZ themedComponent--dark_xIcU"></a></div><div class="footer__copyright">Copyright © 2026 Meta Platforms, Inc. Built with Docusaurus.</div></div></div></footer></div>
23+
</body>
24+
</html>

CNAME

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
flow.org

_src/cli/apply-code-action.md

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,140 @@
1+
---
2+
title: Apply Code Action
3+
slug: /cli/apply-code-action
4+
description: "Apply LSP code actions like autofixes and code transformations from the command line, useful for scripting and batch-fixing."
5+
---
6+
7+
The `apply-code-action` command exposes LSP code actions via the CLI, allowing you to apply autofixes and code transformations without an editor. This is useful for scripting, CI pipelines, or batch-fixing files from the command line.
8+
9+
## Usage {#toc-usage}
10+
11+
```sh
12+
flow apply-code-action SUBCOMMAND [OPTIONS]... FILE
13+
```
14+
15+
The command requires a running Flow server. If one is not already running, it will be started automatically.
16+
17+
## Subcommands {#toc-subcommands}
18+
19+
### `experimental.quickfix` {#toc-experimental-quickfix}
20+
21+
Applies all safe quickfixes to a file. These are the same quickfixes that your editor shows via LSP code actions, such as adding suppression comments or replacing deprecated syntax.
22+
23+
```sh
24+
flow apply-code-action 'experimental.quickfix' [OPTIONS] FILE
25+
```
26+
27+
By default, only safe quickfixes are applied. You can optionally include one additional best-effort fix using the `--include-best-effort-fix` flag. Best-effort fixes may change the runtime semantics of your program (for example, adding a type annotation to a variable declaration to satisfy a type error).
28+
29+
**Options:**
30+
31+
- `--in-place`: Overwrite the input file with the result. Without this flag, the transformed file contents are printed to stdout.
32+
- `--include-best-effort-fix`: Include one additional best-effort quickfix beyond the safe fixes.
33+
34+
**Example:**
35+
36+
```sh
37+
# Print the file with all safe quickfixes applied
38+
flow apply-code-action 'experimental.quickfix' src/app.js
39+
40+
# Apply safe quickfixes and overwrite the file
41+
flow apply-code-action 'experimental.quickfix' --in-place src/app.js
42+
43+
# Also apply one best-effort fix
44+
flow apply-code-action 'experimental.quickfix' --include-best-effort-fix src/app.js
45+
```
46+
47+
### `source.addMissingImports` {#toc-source-add-missing-imports}
48+
49+
Adds missing import statements for unresolved references in a file. Flow resolves each unbound name to an export in your project and inserts the appropriate `import` statement.
50+
51+
```sh
52+
flow apply-code-action 'source.addMissingImports' [OPTIONS] FILE
53+
```
54+
55+
**Options:**
56+
57+
- `--in-place`: Overwrite the input file with the result. Without this flag, the transformed file contents are printed to stdout.
58+
59+
**Example:**
60+
61+
Given a file `app.js` that references `OtherModule` without importing it:
62+
63+
```js
64+
// @flow
65+
66+
OtherModule;
67+
```
68+
69+
Running the command:
70+
71+
```sh
72+
flow apply-code-action 'source.addMissingImports' app.js
73+
```
74+
75+
produces output with the import added:
76+
77+
```js
78+
// @flow
79+
80+
import OtherModule from "./OtherModule";
81+
82+
OtherModule;
83+
```
84+
85+
To update the file in place:
86+
87+
```sh
88+
flow apply-code-action 'source.addMissingImports' --in-place app.js
89+
```
90+
91+
### `suggestImports` {#toc-suggest-imports}
92+
93+
Lists import suggestions for all unbound names in a file, ranked by usage. Unlike the other subcommands, this does not modify the file. Instead, it outputs a JSON object describing the available import code actions for each unresolved name.
94+
95+
```sh
96+
flow apply-code-action suggestImports [OPTIONS] FILE
97+
```
98+
99+
**Options:**
100+
101+
- `--json`: Output results in JSON format (default behavior for this subcommand).
102+
- `--pretty`: Pretty-print the JSON output.
103+
104+
**Example:**
105+
106+
```sh
107+
flow apply-code-action suggestImports --pretty src/app.js
108+
```
109+
110+
The output is a JSON object keyed by unbound name, where each value is an array of possible import actions:
111+
112+
```json
113+
{
114+
"OtherModule": [
115+
{
116+
"title": "Import default from ./OtherModule",
117+
"kind": "quickfix",
118+
"edit": {
119+
"changes": {
120+
"file:///path/to/app.js": [
121+
{
122+
"newText": "import OtherModule from \"./OtherModule\";\n\n",
123+
"range": {
124+
"start": { "character": 0, "line": 1 },
125+
"end": { "character": 0, "line": 1 }
126+
}
127+
}
128+
]
129+
}
130+
}
131+
}
132+
]
133+
}
134+
```
135+
136+
When multiple modules export the same name, all candidates are listed so you can choose the appropriate one.
137+
138+
## See Also {#toc-see-also}
139+
140+
- [Editor Setup](../editors/index.md) — IDE integrations that provide code actions interactively

_src/cli/coverage.md

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
---
2+
title: Flow Coverage
3+
slug: /cli/coverage
4+
description: "Measure how much of your code is covered by Flow's type checking, based on the presence of the any type in inferred expressions."
5+
---
6+
The coverage command provides a metric of the amount of checking that Flow has
7+
performed on each part of your code. A program with high Flow coverage should
8+
increase your confidence that Flow has detected any potential runtime errors.
9+
10+
The determining factor for this is the presence of [`any`](../types/any.md) in the
11+
inferred type of each expression. An expression whose inferred type is `any` is
12+
considered *uncovered*, otherwise it is considered *covered*.
13+
14+
To see why this metric was chosen for determining Flow's effectiveness, consider
15+
the example
16+
17+
```js flow-check
18+
const one: any = 1;
19+
one();
20+
```
21+
22+
This code leads to a runtime type error, since we are attempting to perform a call
23+
on a number. Flow, however, does not flag an error here, because we have annotated
24+
variable `one` as `any`. Flow's checking is effectively turned off whenever `any`
25+
is involved, so it will silently allow the call. The use of this *unsafe* type has
26+
rendered the type checker ineffective, and the coverage metric is here to surface
27+
this, by reporting all instances of `one` as uncovered.
28+
29+
## Design Space {#toc-design-space}
30+
31+
**Which types should be "covered"?**
32+
33+
What was described above is a rather coarse grained way to determine coverage. One
34+
could imagine a criterion that flags expressions as uncovered if *any* part of their
35+
type includes `any`, for example `Array<any>`. While there is value in a metric like
36+
this, the "uncovered" part of the type will typically be uncovered through various
37+
operations on values of this type. For example, in the code
38+
39+
```js flow-check
40+
declare const arr: Array<any>;
41+
arr.forEach(x => {});
42+
```
43+
44+
the parameter `x` will be flagged as uncovered. Also, in practice, a strict criterion
45+
like this would be too noisy and rather expensive to compute on the fly.
46+
47+
**Union types**
48+
49+
An exception to this principle are union types: the type `number | any` is considered
50+
*uncovered*, even though technically `any` is not the top-level constructor.
51+
Unions merely encode an option among *a set of* other types. In that sense we are
52+
conservatively viewing an expression as uncovered, when at least one possible type
53+
of that expression causes limited checking. For example, in the code
54+
55+
```js flow-check
56+
let x: number | any = 1;
57+
x = "a";
58+
```
59+
60+
Flow will let you assign anything to `x`, which reduces confidence in the use
61+
of `x` as a number. Thus `x` is considered uncovered.
62+
63+
**The empty type**
64+
65+
An interesting type from a coverage perspective is the [`empty`](../types/empty.md) type.
66+
This type roughly corresponds to *dead code*. As such checking around expressions with
67+
type `empty` is more relaxed, but for a good reason: this code will not be executed at
68+
runtime. Since it is a common practice to clean up such code, Flow coverage will
69+
also report code whose type is inferred to be `empty`, but distinguishes it from
70+
the case of `any`.
71+
72+
73+
## Command Line Use {#toc-command-line-use}
74+
75+
To find out the coverage of a file foo.js with the following contents
76+
77+
```js flow-check
78+
function add(one: any, two: any): number {
79+
return one + two;
80+
}
81+
82+
add(1, 2);
83+
```
84+
85+
you can issue the following command
86+
87+
```
88+
$ flow coverage file.js
89+
Covered: 50.00% (5 of 10 expressions)
90+
```
91+
This output means that 5 out of the 10 nodes of this program were inferred to have type
92+
`any`. To see exactly which parts are uncovered you can also pass one of the following
93+
flags:
94+
* `--color`: This will print foo.js on the terminal with the uncovered locations in
95+
red color. E.g. `flow coverage --color file.js`
96+
* `--json`: This will list out all location spans that are uncovered under
97+
the tag `"uncovered_locs"`. E.g. `flow coverage --json file.js`
98+
99+
Finally, as an example of dead code, consider the code:
100+
101+
```js flow-check
102+
function f(x: 'a' | 'b') {
103+
if (x === 'a') {
104+
// ...
105+
} else if (x === 'b') {
106+
// ...
107+
} else {
108+
x;
109+
}
110+
}
111+
```
112+
113+
The final `else` clause should never be reached, as we've already checked for both members of the union.
114+
Because of this, `x` is inferred to have the type `empty` in that branch.
115+
116+
In the colored version of this command, these parts appear in blue color,
117+
and in the JSON version they are under the field `"empty_locs"`.
118+
119+
**Use on multiple files**
120+
121+
If you want to check coverage of multiple files at once, Flow offers the
122+
`batch-coverage` command:
123+
```
124+
$ flow batch-coverage dir/
125+
```
126+
will report coverage statistics for each file under `dir/`, as well as aggregate
127+
results.
128+
129+
Note that `batch-coverage` requires a non-lazy Flow server.
130+
131+
## See Also {#toc-see-also}
132+
133+
- [Any](../types/any.md) — the type that reduces coverage, and how to avoid it
134+
- [Unknown](../types/unknown.md) — the safe alternative to `any` that maintains coverage

0 commit comments

Comments
 (0)