JSPM

  • Created
  • Published
  • Downloads 4129882
  • Score
    100M100P100Q207892F
  • License BSD-3-Clause

Flowtype linting rules for ESLint.

Package Exports

  • eslint-plugin-flowtype
  • eslint-plugin-flowtype/dist/utilities

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (eslint-plugin-flowtype) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

eslint-plugin-flowtype

NPM version Travis build status js-canonical-style

Flow type linting rules for ESLint.

Installation

  1. Install ESLint.
  2. Install babel-eslint parser (ESLint parser does not support type annotations).
  3. Install eslint-plugin-flowtype plugin.
npm install eslint
npm install babel-eslint
npm install eslint-plugin-flowtype

Configuration

  1. Set parser property to babel-eslint.
  2. Add plugins section and specify eslint-plugin-flowtype as a plugin.
  3. 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) => {}
// Message: Missing "foo" parameter type annotation.

(foo = 'FOO') => {}
// Message: Missing "foo" parameter type annotation.

(...foo) => {}
// Message: Missing "foo" parameter type annotation.

({foo}) => {}
// Message: Missing "{foo}" parameter type annotation.

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"; }
// Message: Missing return type annotation.

// Options: ["always"]
(foo) => { return "foo"; }
// Message: Missing return type annotation.

(foo): undefined => { return; }
// Message: Must not annotate undefined return type.

(foo): undefined => { return undefined; }
// Message: Must not annotate undefined return type.

// Options: ["always",{"annotateUndefined":"never"}]
(foo): undefined => { return; }
// Message: Must not annotate undefined return type.

// Options: ["always",{"annotateUndefined":"always"}]
(foo) => { return; }
// Message: Must annotate undefined return type.

// Options: ["always",{"annotateUndefined":"never"}]
(foo): undefined => { return undefined; }
// Message: Must not annotate undefined return type.

// Options: ["always",{"annotateUndefined":"always"}]
(foo) => { return undefined; }
// Message: Must annotate undefined return type.

The following patterns are not considered problems:

(foo): string => {}

// Options: ["always"]
(foo): string => {}

(foo) => { return; }

(foo) => { return undefined; }

// Options: ["always",{"annotateUndefined":"always"}]
(foo): undefined => { return; }

// Options: ["always",{"annotateUndefined":"never"}]
(foo) => { return; }

// Options: ["always",{"annotateUndefined":"never"}]
(foo) => { return undefined; }

// Options: ["always",{"annotateUndefined":"always"}]
(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:

// Options: ["never"]
(foo: string) => {}
// Message: There must be no space after "foo" parameter type annotation colon.

// Options: ["always"]
(foo:string) => {}
// Message: There must be a space after "foo" parameter type annotation colon.

// Options: ["always"]
(foo:  string) => {}
// Message: There must be 1 space after "foo" parameter type annotation colon.

The following patterns are not considered problems:

(foo) => {}

(foo: string) => {}

// Options: ["never"]
(foo:string) => {}

// Options: ["always"]
(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:

// Options: ["never"]
(foo : string) => {}
// Message: There must be no space before "foo" parameter type annotation colon.

// Options: ["always"]
(foo: string) => {}
// Message: There must be a space before "foo" parameter type annotation colon.

// Options: ["always"]
(foo  : string) => {}
// Message: There must be 1 space before "foo" parameter type annotation colon.

The following patterns are not considered problems:

(foo) => {}

(foo: string) => {}

// Options: ["never"]
(foo: string) => {}

// Options: ["always"]
(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.