PyCharm 2019.2 Help

Flow

Flow is a static type checker that brings type annotations to JavaScript. PyCharm recognizes Flow structures and provides syntax highlighting for them on all operating systems.

Installing and configuring Flow

In the embedded Terminal (Alt+F12), type one of the following commands:

  • npm install --global flow-bin to install Flow globally.

  • npm install --save-dev flow-bin to install Flow as a development dependency.

Learn more from the Flow official website.

To have PyCharm recognize Flow structures, provide correct syntax highlighting, report errors properly, and avoid false-positive error highlighting, change the JavaScript language level in your project to Flow, add a .flowconfig configuration file to your project, and supply every file to be checked with a // @flow comment on top.

Change the project language level to Flow

  1. In the Settings/Preferences dialog (Ctrl+Alt+S), go to Languages and Frameworks | JavaScript. The JavaScript page opens.

  2. From the JavaScript Language Version list, choose Flow.

  3. In the Flow package or executable field, specify the path to the node_modules\flow-bin node_modules/flow-bin package or the Flow binary executable file. To use node_modules\.bin\flownode_modules/ .bin/flow make sure the path to Node.js is added to the PATH environment variable.

  4. In the Use Flow server for: area, specify the basis for coding assistance by selecting or clearing the following checkboxes:

    • Type checking: When this checkbox is selected, syntax and error highlighting is provided based on the data received from the Flow server. When the checkbox is cleared, only the basic internal PyCharm highlighting is available.

    • Navigation, code completion, and type hinting: When this checkbox is selected, suggestion lists for reference resolution and code completiong contain both suggestions retrieved from integration with Flow and suggestions calculated by PyCharm. When the checkbox is cleared, references are resolved through PyCharm calculation only.

    The checkboxes are available only when the path to the Flow executable file is specified.
  5. Keep the Save all modified files automatically checkbox selected to ensure that Flow is applied continuously because Flow checks the current files only after all the other modified files are saved.

Enable Flow

  1. To add a .flowconfig, open the embedded Terminal (Alt+F12) and type:

    flow init

    To add .flowconfig to a specific folder, type:

    cd <path to the folder to check>
    flow init

  2. To enable Flow in a file, add a // @flow comment at the top of the file: just type flow, press Tab, and PyCharm will expand it into // @flow.

    If you still don't have a .flowconfig yet, PyCharm shows a tooltip prompting you to add a configuration file to the current folder.

    Tooltip: Add .flowconfig to the current folder

    To choose between the current folder and the project root, click More actions or press Alt+Enter.

    Tooltip: More actions

Monitoring errors

PyCharm lets you view errors detected by Flow in the dedicated Flow tool window, which becomes available after you add at least one .flowconfig file to your project. To open the tool window, select View | Tool Windows | Flow from the main menu.

The Flow tool window consists of two panes.

  • The Errors pane shows a list of all the discrepancies detected in the file which is opened in the active editor tab. At the top the full path to the file is displayed.

    When you open the Flow tool window, only the Errors pane is displayed.

  • The Project Errors pane shows a list of all the discrepancies detected in all the files in the current project after you run Flow against the entire project by clicking icon_flow_tool_window_show_all_errors.png on the toolbar. The error messages are grouped by files in which they were detected.

Toolbar

The toolbar is common for the Current Errors and the Project Errors panes.

Item

Tooltip
and Shortcut

Description

icon_flow_tool_window_show_all_errors.png

Show all errors

Click this button to switch to the Project Errors pane and view all the discrepancies detected in the current project.

help

Help

Use this button to navigate to the help topic for the tool window.

the Close button

Close Ctrl+Shift+F4

Click this button to terminate the Flow type checker and close the tool window.

Expand all
Collapse all

Expand all
Ctrl+NumPad Plus
Collapse all
Ctrl+NumPad -

Use these buttons to have all nodes expanded or collapsed.

Clear All

Clear All

Click this button to remove all the error messages from the currently active pane.

Context Menu

The context menu is common for the Errors and the Project Errors panes.

Item

Description

Jump to source

Choose this option to open the file where the selected problem was detected and navigate to the fragment of code which caused the error.

Copy

Choose this option to copy the selected error message with the information on the file, the line, and the column where the error occurred.

Last modified: 13 September 2019

See Also

Reference:

Language and Framework-Specific Guidelines: