Skip to content

johnsonw/eslint-plugin-flowtype

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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,
            "always",
            {
                "annotateUndefined": "never"
            }
        ],
        "flowtype/space-after-type-colon": [
            1,
            "always"
        ],
        "flowtype/space-before-type-colon": [
            1,
            "never"
        ],
        "flowtype/type-id-match": [
            1,
            "^([A-Z][a-z0-9]+)+Type$"
        ]
    }
}

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.

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

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

The following patterns are not considered problems:

(foo: string) => {}

(foo: string = 'FOO') => {}

(...foo: string) => {}

({foo}: {foo: string}) => {}

([foo]: Array) => {}

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: ["never"]
export default function (foo: string) {}
// Message: There must be no space after "foo" parameter type annotation colon.

// Options: ["never"]
function foo (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) => {}

type-id-match

Enforces a consistent naming pattern for type aliases.

Options

This rule needs a text RegExp to operate with Its signature is as follows:

{
    "rules": {
        "flowtype/type-id-match": [
            2,
            "^([A-Z][a-z0-9]+)+Type$"
        ]
    }
}

'^([A-Z][a-z0-9]+)+Type is the default pattern.

The following patterns are considered problems:

type foo = {};
// Message: Type identifier 'foo' does not match pattern '/^Type([A-Z][a-z0-9]+)+$/'.

// Options: ["^foo$"]
type TypeFoo = {};
// Message: Type identifier 'TypeFoo' does not match pattern '/^foo$/'.

The following patterns are not considered problems:

type TypeFoo = {};

// Options: ["^foo$"]
type foo = {};

About

Flow type linting rules for ESLint.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%