eslint-plugin-flowtype
![js-canonical-style](https://img.shields.io/badge/code%20style-canonical-blue.svg?style=flat-square)
Flow type linting rules for ESLint.
Installation
- Install ESLint.
- Install
babel-eslint
parser (ESLint parser does not support type annotations). - Install
eslint-plugin-flowtype
plugin.
npm install eslint
npm install babel-eslint
npm install eslint-plugin-flowtype
Configuration
- Set
parser
property to babel-eslint
. - Add
plugins
section and specify eslint-plugin-flowtype
as a plugin. - Enable rules.
{
"parser": "babel-eslint",
"plugins": [
"flowtype"
],
"rules": {
"flowtype/require-parameter-type": 1,
"flowtype/require-return-type": 1,
"flowtype/space-after-type-colon": [
1,
"always"
],
"flowtype/space-before-type-colon": [
1,
"never"
]
}
}
Rules
require-parameter-type
Requires that all function parameters have type annotations.
The following patterns are considered problems:
(foo) => {}
(foo = 'FOO') => {}
(...foo) => {}
({foo}) => {}
The following patterns are not considered problems:
(foo: string) => {}
(foo: string = 'FOO') => {}
(...foo: string) => {}
({foo}: {foo: string}) => {}
require-return-type
Requires that functions have return type annotation.
The following patterns are considered problems:
(foo) => { return "foo"; }
(foo) => { return "foo"; }
(foo): undefined => { return; }
(foo): undefined => { return undefined; }
(foo): undefined => { return; }
(foo) => { return; }
(foo): undefined => { return undefined; }
(foo) => { return undefined; }
The following patterns are not considered problems:
(foo): string => {}
(foo): string => {}
(foo) => { return; }
(foo) => { return undefined; }
(foo): undefined => { return; }
(foo) => { return; }
(foo) => { return undefined; }
(foo): undefined => { return undefined; }
space-after-type-colon
Enforces consistent spacing after the type annotation colon.
This rule takes one argument. If it is 'always'
then a problem is raised when there is no space after the type annotation colon. If it is 'never'
then a problem is raised when there is a space after the type annotation colon. The default value is 'always'
.
The following patterns are considered problems:
(foo: string) => {}
(foo:string) => {}
(foo: string) => {}
The following patterns are not considered problems:
(foo) => {}
(foo: string) => {}
(foo:string) => {}
(foo: string) => {}
space-before-type-colon
Enforces consistent spacing before the type annotation colon.
This rule takes one argument. If it is 'always'
then a problem is raised when there is no space before the type annotation colon. If it is 'never'
then a problem is raised when there is a space before the type annotation colon. The default value is 'never'
.
The following patterns are considered problems:
(foo : string) => {}
(foo: string) => {}
(foo : string) => {}
The following patterns are not considered problems:
(foo) => {}
(foo: string) => {}
(foo: string) => {}
(foo : string) => {}
eslint-plugin-flowtype
v1
eslint-plugin-flowtype
v1 served a different purpose:
A plugin for ESLint that strips FlowType type annonations before linting the files.
You can find the source code for v1 at:
https://github.com/gcazaciuc/eslint-plugin-flowtype
Reference to the original codebase included for historical reference purposes.