Using the Flow Type Checker
RubyMine provides basic support of Flow static type checker that brings type annotations to JavaScript. This support involves recognition and syntax highlighting of Flow structures on all operating systems. If you are using Unix or OS X, you can also run Flow in the command-line mode.
On this page:
- Before you start
- Installing Flow
- Installing Flow globally
- Installing Flow in a project
- Configuring Flow in RubyMine
Before you start
- Install and enable the NodeJS repository plugin as described in Installing, Updating and Uninstalling Repository Plugins and Enabling and Disabling Plugins.
- Download and install the Node.js runtime environment.
-
Configure the Node.js interpreter in RubyMine:
- Open the Settings / Preferences Dialog by choosing for Windows and Linux or for OS X, and click Node.js and NPM under Languages&Frameworks.
- On the Node.js and NPM page that opens, specify the location of the desired Node.js interpreter.
Installing Flow
The easiest way to install the Flow type checker is to use the Node Package Manager (npm), which is a part of Node.js. See Installing and Removing External Software Using Node Package Manager for details.
Depending on the desired location of the Flow type checker executable file, choose one of the following methods:
- Install the type checker globally at the RubyMine level so it can be used in any RubyMine project.
- Install the type checker in a specific project and thus restrict its use to this project.
- Install the type checker in a project as a development dependency.
In either installation mode, make sure that the parent folder of the Flow type checker is added to the PATH
variable.
This enables you to launch the type checker from any folder.
RubyMine provides user interface both for global and project installation as well as supports installation through the command line.
Installing Flow globally
Global installation makes a type checker available at the RubyMine level so it can be used in any RubyMine project.
Moreover, during installation the parent folder of the type checker is automatically added to the PATH
variable,
which enables you to launch the type checker from any folder.
To install the type checker globally, do one of the following:
-
Run the installation from the command line in the global mode:
- Launch the embedded Terminal by hovering your mouse pointer over in the lower left corner of RubyMine and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
-
Switch to the directory where NPM is stored or define a
PATH
variable for it so it is available from any folder, see Installing NodeJs. -
Type the following command at the command line prompt:
npm install -g flow-bin
The
-g
key makes the type checker run in the global mode. Because the installation is performed through NPM, the Flow type checker is installed in thenpm
folder. Make sure this parent folder is added to thePATH
variable. This enables you to launch the type checker from any folder.For more details on the NPM operation modes, see npm documentation. For more information about installing the Flow type checker, see https://npmjs.org/package/flow-bin.
-
Run NPM from RubyMine using the Node.js and NPM page of the Settings dialog box.
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for OS X, and click Node.js and NPM under Languages&Frameworks.
- On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click .
- In the Available Packages dialog box that opens, select the required package to install.
-
Select the Options check box and type
-g
in the text box next to it. - Optionally specify the product version and click Install Package to start installation.
Installing Flow in a project
Installing a type checker in a specific project restricts its use to this project. To run project installation, do one of the following:
-
Run the installation from the command line:
- Launch the embedded Terminal by hovering your mouse pointer over in the lower left corner of RubyMine and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
-
Switch to the project root folder and type the following command at the command line prompt:
npm install flow-bin
-
Run NPM from RubyMine using the Node.js and NPM page of the Settings dialog box.
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for OS X, and click Node.js and NPM under Languages & Frameworks.
- On the Node.js and NPM page that opens, the Packages area shows all the Node.js-dependent packages that are currently installed on your computer, both at the global and at the project level. Click .
- In the Available Packages dialog box that opens, select the required package.
- Optionally specify the product version and click Install Package to start installation.
Project level installation is helpful and reliable in template-based projects
of the type Node Boilerplate or Node.js Express, which already have the node_modules
folder.
The latter is important because NPM installs the Flow type checker
in a node_modules
folder. If your project already contains such folder, the Flow type checker is installed there.
Projects of other types or empty projects may not have a node_modules
folder.
In this case npm goes upwards in the folder tree and installs the Flow type checker
in the first detected node_modules
folder. Keep in mind that this detected node_modules
folder may be outside your current project root.
Finally, if no node_modules
folder is detected in the folder tree either,
the folder is created right under the current project root and the Flow type checker is installed there.
In either case, make sure that the parent folder of the Flow type checker is added to the PATH
variable.
This enables you to launch the type checker from any folder.
For more details, see Getting Started with Flow.
Configuring Flow in RubyMine
To have RubyMine recognize Flow structures, provide correct syntax highlighting, report errors properly, and avoid false-positive error highlighting,
change the JavaScript language level to Flow, add a .flowconfig
configuration file to your project,
and supply every file to be checked with a // @flow
comment on top.
-
To change the language level to Flow:
- Open the Settings / Preferences Dialog by pressing Ctrl+Alt+S or by choosing for Windows and Linux or for OS X, and click JavaScript under Languages&Frameworks.
- On the JavaScript page that opens, choose Flow from the JavaScript Language Version drop-down list.
- In the Flow executable field, specify the path to the Flow executable file.
-
In the Use Flow server for: area,
specify the basis for coding assistance by selecting or clearing the following check boxes:
- Type checking: When this check box is selected, syntax and error highlighting is provided based on the data received from the Flow server. When the check box is cleared, only the basic internal RubyMine highlighting is available.
- Navigation, code completion, and type hinting: When this check box is selected, suggestion lists for reference resolution and code completiong contain both suggestions retrieved from integration with Flow and suggestions calculated by RubyMine. When the check box is cleared, references are resolved through RubyMine calculation only.
- Code highlighting and built-in inspections: Select this checkbox to power native Flow code highlighting and built-in inspections. Please note that enabling this option may cause performance problems. By default, the check box is cleared.
The check boxes are available only when the path to the Flow executable file is specified.
-
To have a
.flowconfig
configuration file generated in your project:- Launch the embedded Terminal by hovering your mouse pointer over in the lower left corner of RubyMine and choosing Terminal from the menu (see Working with Embedded Local Terminal for details).
-
Run the
flow init
command at the command line prompt.
-
To have a file checked with the Flow checker, add a
// @flow
comment at the top of it: just typeflow
and press ? and RubyMine will expand it into// @flow
.