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/boolean-style": [
2,
"boolean"
],
"flowtype/define-flow-type": 1,
"flowtype/delimiter-dangle": [
2,
"never"
],
"flowtype/generic-spacing": [
2,
"never"
],
"flowtype/no-weak-types": 2,
"flowtype/require-parameter-type": 2,
"flowtype/require-return-type": [
2,
"always",
{
"annotateUndefined": "never"
}
],
"flowtype/require-valid-file-annotation": 2,
"flowtype/semi": [
2,
"always"
],
"flowtype/space-after-type-colon": [
2,
"always"
],
"flowtype/space-before-generic-bracket": [
2,
"never"
],
"flowtype/space-before-type-colon": [
2,
"never"
],
"flowtype/type-id-match": [
2,
"^([A-Z][a-z0-9]+)+Type$"
],
"flowtype/union-intersection-spacing": [
2,
"always"
],
"flowtype/use-flow-type": 1,
"flowtype/valid-syntax": 1
},
"settings": {
"flowtype": {
"onlyFilesWithFlowAnnotation": false
}
}
}
Shareable configurations
Recommended
This plugin exports a recommended configuration that enforces Flow type good practices.
To enable this configuration use the extends property in your .eslintrc
config file:
{
"extends": [
"plugin:flowtype/recommended"
],
"plugins": [
"flowtype"
]
}
See ESLint documentation for more information about extending configuration files.
Settings
onlyFilesWithFlowAnnotation
When true
, only checks files with a @flow
annotation in the first comment.
{
"settings": {
"flowtype": {
"onlyFilesWithFlowAnnotation": true
}
}
}
Rules
boolean-style
The --fix
option on the command line automatically fixes problems reported by this rule.
Enforces a particular style for boolean type annotations. This rule takes one argument.
If it is 'boolean'
then a problem is raised when using bool
instead of boolean
.
If it is 'bool'
then a problem is raised when using boolean
instead of bool
.
The default value is 'boolean'
.
The following patterns are considered problems:
type X = bool
type X = bool
type X = boolean
The following patterns are not considered problems:
type X = boolean
type X = boolean
type X = bool
define-flow-type
Marks Flow type identifiers as defined.
Used to suppress no-undef
reporting of type identifiers.
The following patterns are not considered problems:
var a: AType
var a: AType; var b: AType
var a; (a: AType)
var a: AType<BType>
type A = AType
function f(a: AType) {}
function f(a: AType.a) {}
function f(a: AType.a.b) {}
function f(a): AType {}; var a: AType
function f(a): AType {}
class C { a: AType }
class C { a: AType.a }
class C { a: AType.a.b }
class C implements AType {}
interface AType {}
({ a: ({b() {}}: AType) })
type X = {Y<AType>(): BType}
interface AType<BType> {}
var a: AType
var a: AType; var b: AType
var a; (a: AType)
var a: AType<BType>
type A = AType
function f(a: AType) {}
function f(a: AType.a) {}
function f(a: AType.a.b) {}
function f(a): AType {}; var a: AType
function f(a): AType {}
class C { a: AType }
class C { a: AType.a }
class C { a: AType.a.b }
class C implements AType {}
interface AType {}
({ a: ({b() {}}: AType) })
type X = {Y<AType>(): BType}
interface AType<BType> {}
delimiter-dangle
The --fix
option on the command line automatically fixes problems reported by this rule.
Enforces consistent use of trailing commas in Object and Tuple annotations.
This rule takes one argument which mirrors ESLint's default comma-dangle
rule.
If it is 'never'
then a problem is raised when there is a trailing comma.
If it is 'always'
then a problem is raised when there is no trailing comma.
If it is 'always-multiline'
then a problem is raised when there is no trailing comma on a multi-line definition, or there is a trailing comma on a single-line definition.
If it is 'only-multiline'
then a problem is raised when there is a trailing comma on a single-line definition. It allows, but does not enforce, trailing commas on multi-line definitions.
The default value is 'never'
.
The following patterns are considered problems:
type X = { foo: string, }
type X = { foo: string, }
type X = { foo: string; }
type X = {
foo: string,
}
type X = { foo: string }
type X = {
foo: string
}
type X = { foo: string, }
type X = {
foo: string
}
type X = { foo: string; }
type X = { [key: string]: number, }
type X = { [key: string]: number }
type X = { [key: string]: number, }
type X = {
[key: string]: number
}
type X = { [key: string]: number; }
type X = { [key: string]: number, foo: string, }
type X = {
[key: string]: number,
foo: string,
}
type X = {
[key: string]: number,
aReallyLongPropertyNameHere: string,
}
type X = { [key: string]: number, foo: string }
type X = {
[key: string]: number;
foo: string
}
type X = { [key: string]: number, foo: string, }
type X = {
[key: string]: number,
foo: string
}
type X = { [key: string]: number, foo: string, }
type X = { foo: string, [key: string]: number, }
type X = {
foo: string,
[key: string]: number,
}
type X = {
aReallyLongPropertyNameHere: string,
[key: string]: number,
}
type X = { foo: string, [key: string]: number }
type X = { foo: string; [key: string]: number }
type X = { foo: string, [key: string]: number; }
type X = {
foo: string,
[key: string]: number
}
type X = { foo: string, [key: string]: number; }
type X = [string, number,]
type X = [string, number,]
type X = [
string,
number,
]
type X = [string, number]
type X = [
string,
number
]
type X = [string, number,]
type X = [
foo, string
]
type X = [ number, string, ]
The following patterns are not considered problems:
type X = { foo: string }
type X = { foo: string }
type X = { foo: string, }
type X = { foo: string; }
type X = {
foo: string
}
type X = {
foo: string,
}
type X = { foo: string }
type X = {
foo: string,
}
type X = {
foo: string;
}
type X = { foo: string }
type X = {
foo: string
}
type X = {
foo: string,
}
type X = {
foo: string;
}
type X = {}
type X = {}
type X = {}
type X = {}
type X = { [key: string]: number }
type X = { [key: string]: number, }
type X = { [key: string]: number; }
type X = { [key: string]: number }
type X = {
[key: string]: number,
}
type X = {
[key: string]: number,
}
type X = {
[key: string]: number
}
type X = { [key: string]: number }
type X = { [key: string]: number, foo: string }
type X = { [key: string]: number, foo: string, }
type X = { [key: string]: number; foo: string; }
type X = { [key: string]: number, foo: string }
type X = {
[key: string]: number,
foo: string,
}
type X = {
[key: string]: number,
foo: string,
}
type X = {
[key: string]: number;
foo: string
}
type X = { [key: string]: number, foo: string }
type X = { foo: string, [key: string]: number }
type X = { foo: string, [key: string]: number, }
type X = { foo: string; [key: string]: number; }
type X = { foo: string, [key: string]: number }
type X = {
foo: string,
[key: string]: number,
}
type X = {
foo: string,
[key: string]: number,
}
type X = {
foo: string;
[key: string]: number
}
type X = { foo: string, [key: string]: number }
type X = [string, number]
type X = [string, number]
type X = [
string,
number
]
type X = [string, number,]
type X = [
string,
number,
]
type X = [ foo, string ]
type X = [
foo, string,
]
type X = [ number, string ]
type X = [
number,
string
]
type X = [
number,
string,
]
type X = []
type X = []
type X = []
type X = []
generic-spacing
The --fix
option on the command line automatically fixes problems reported by this rule.
Enforces consistent spacing within generic type annotation parameters.
This rule takes one argument. If it is 'never'
then a problem is raised when there is a space surrounding the generic type parameters. If it is 'always'
then a problem is raised when there is no space surrounding the generic type parameters.
The default value is 'never'
.
The following patterns are considered problems:
type X = Promise< string>
type X = Promise< string>
type X = FooBar<string >
type X = Promise< string >
type X = Promise< (foo), bar, (((baz))) >
type X = Promise<string >
type X = FooBar< string>
type X = Promise<string>
type X = Promise<(foo), bar, (((baz)))>
type X = FooBar< string >
type X = FooBar< string >
type X = Promise< (foo), bar, (((baz))) >
The following patterns are not considered problems:
type X = Promise<string>
type X = Promise<(string)>
type X = Promise<(foo), bar, (((baz)))>
type X = Promise< string >
type X = Promise< (string) >
type X = Promise< (foo), bar, (((baz))) >
no-dupe-keys
Checks for duplicate properties in Object annotations.
This rule mirrors ESLint's no-dupe-keys rule.
{
"rules": {
"flowtype/no-dupe-keys": 2
}
}
The following patterns are considered problems:
type FooType = { a: number, b: string, a: number }
type FooType = { a: number, b: string, a: string }
The following patterns are not considered problems:
type FooType = { a: number, b: string, c: number }
no-weak-types
Warns against weak type annotations any, Object and Function.
These types can cause flow to silently skip over portions of your code,
which would have otherwise caused type errors.
This rule optionally takes one argument, an object to configure which type warnings to enable. By default, all of the
warnings are enabled. e.g. to disable the any
warning (allowing it to exist in your code), while continuing to warn
about Object
and Function
:
{
"rules": {
"flowtype/no-weak-types": [2, {
"any": false,
"Object": true,
"Function": true
}]
}
}
{
"rules": {
"flowtype/no-weak-types": [2, {
"any": false
}]
}
}
The following patterns are considered problems:
function foo(thing): any {}
function foo(thing): Promise<any> {}
function foo(thing): Promise<Promise<any>> {}
function foo(thing): Object {}
function foo(thing): Promise<Object> {}
function foo(thing): Promise<Promise<Object>> {}
function foo(thing): Function {}
function foo(thing): Promise<Function> {}
function foo(thing): Promise<Promise<Function>> {}
(foo: any) => {}
(foo: Function) => {}
(foo?: any) => {}
(foo?: Function) => {}
(foo: { a: any }) => {}
(foo: { a: Object }) => {}
(foo: any[]) => {}
type Foo = any
type Foo = Function
type Foo = { a: any }
type Foo = { a: Object }
type Foo = { (a: Object): string }
type Foo = { (a: string): Function }
function foo(thing: any) {}
function foo(thing: Object) {}
var foo: Function
var foo: Object
class Foo { props: any }
class Foo { props: Object }
var foo: any
type X = any; type Y = Function; type Z = Object
type X = any; type Y = Function; type Z = Object
The following patterns are not considered problems:
function foo(thing): string {}
function foo(thing): Promise<string> {}
function foo(thing): Promise<Promise<string>> {}
(foo?: string) => {}
(foo: ?string) => {}
(foo: { a: string }) => {}
(foo: { a: ?string }) => {}
(foo: string[]) => {}
type Foo = string
type Foo = { a: string }
type Foo = { (a: string): string }
function foo(thing: string) {}
var foo: string
class Foo { props: string }
type X = any; type Y = Object
type X = Function
require-parameter-type
Requires that all function parameters have type annotations.
Options
You can skip all arrow functions by providing the excludeArrowFunctions
option with true
.
Alternatively, you can want to exclude only concise arrow functions (e.g. x => x * 2
). Provide excludeArrowFunctions
with expressionsOnly
for this.
{
"rules": {
"flowtype/require-parameter-type": [
2,
{
"excludeArrowFunctions": true
}
]
}
}
{
"rules": {
"flowtype/require-parameter-type": [
2,
{
"excludeArrowFunctions": "expressionsOnly"
}
]
}
}
The following patterns are considered problems:
(foo) => {}
function x(foo) {}
function x(foo) {}
(foo = 'FOO') => {}
(...foo) => {}
({foo}) => {}
([foo]) => {}
({foo = 1} = {}) => {}
(foo) => {}
(foo) => {}
function x(foo) {}
The following patterns are not considered problems:
(foo: string) => {}
(foo: string = 'FOO') => {}
(...foo: string) => {}
({foo}: {foo: string}) => {}
([foo]: Array) => {}
(foo) => {}
(foo) => {}
(foo) => 3
require-return-type
Requires that functions have return type annotation.
Options
You can skip all arrow functions by providing the excludeArrowFunctions
option with true
.
Alternatively, you can want to exclude only concise arrow function (e.g. () => 2
). Provide excludeArrowFunctions
with expressionsOnly
for this.
{
"rules": {
"flowtype/require-return-type": [
2,
"always",
{
"excludeArrowFunctions": true
}
]
}
}
{
"rules": {
"flowtype/require-return-type": [
2,
"always",
{
"excludeArrowFunctions": "expressionsOnly"
}
]
}
}
The following patterns are considered problems:
(foo) => { return "foo"; }
(foo) => { return "foo"; }
(foo) => "foo"
(foo) => ({})
(foo): undefined => { return; }
(foo): void => { return; }
(foo): undefined => { return undefined; }
(foo): void => { return void 0; }
(foo): undefined => { return; }
(foo): void => { return; }
(foo) => { return; }
(foo): undefined => { return undefined; }
(foo) => { return undefined; }
(foo) => { return void 0; }
(foo) => { return 1; }
(foo) => { return undefined; }
async () => { return 2; }
async () => {}
async function x() {}
async () => { return; }
function* x() {}
() => { return 3; }
async () => { return 4; }
The following patterns are not considered problems:
(foo): string => {}
(foo): string => {}
(foo) => { return; }
(foo): Object => ( {} )
(foo) => { return undefined; }
(foo) => { return void 0; }
(foo): undefined => { return; }
(foo): void => { return; }
(foo) => { return; }
(foo) => { return undefined; }
(foo) => { return void 0; }
(foo): undefined => { return undefined; }
(foo): void => { return void 0; }
(foo) => { return 1; }
(foo) => { return undefined; }
async function doThing(): Promise<void> {}
function* doThing(): Generator<number, void, void> { yield 2; }
async (foo): Promise<number> => { return 3; }
() => 3
() => { return 4; }
() => undefined
() => undefined
() => { return undefined; }
() => 3
async () => 3
require-valid-file-annotation
Makes sure that files have a valid @flow
annotation. It will report annotations with typos (such as // @floww
) or not placed at the top of the file, and optionaly missing annotations.
Options
By default, this rule won't complain if there is no @flow
annotation at all in the file. Passing a "always"
option reports files missing those annotations as well.
{
"rules": {
"flowtype/require-valid-file-annotation": [
2,
"always"
]
}
}
The following patterns are considered problems:
;
;
a;
The following patterns are not considered problems:
a;
a;
a;
a;
a;
a;
a;
a;
semi
The --fix
option on the command line automatically fixes problems reported by this rule.
Enforces consistent use of semicolons after type aliases.
This rule takes one argument. If it is 'never'
then a problem is raised when there is a semicolon after a type alias. If it is 'always'
then a problem is raised when there is no semicolon after a type alias.
The default value is 'always'
.
The following patterns are considered problems:
type FooType = {}
type FooType = {}
type FooType = {};
The following patterns are not considered problems:
type FooType = {};
type FooType = {};
type FooType = { a: number;
b: string;
};
type FooType = { a: number;
b: string;
}
type FooType = {}
space-after-type-colon
The --fix
option on the command line automatically fixes problems reported by this rule.
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:(() => void)) => {}
(foo: (() => void)) => {}
(foo: (() => void)) => {}
({ lorem, ipsum, dolor } : SomeType) => {}
(foo:{ a: string, b: number }) => {}
({ a, b } :{ a: string, b: number }) => {}
([ a, b ] :string[]) => {}
(i?:number) => {}
(i?: number) => {}
(i?: number) => {}
():Object => {}
(): Object => {}
(): Object => {}
():(() => void) => {}
(): (() => void) => {}
(): (() => void) => {}
export default function (foo: string) {}
function foo (foo: string) {}
(foo:string) => {}
function foo (foo:string) {}
async function foo({ lorem, ipsum, dolor }:SomeType) {}
function x(i?:number) {}
function x(i?: number) {}
function x(i?: number) {}
type X = (foo:number) => string
type X = (foo: number) => string
type X = (foo: number) => string
type X = (foo:?number) => string
type X = (foo:(number)) => string
type X = (foo:((number))) => string
type X = (foo: ((number))) => string
type X = (foo: ((number))) => string
type X = (foo:?(number)) => string
type TArrayPredicate = (el: T, i?:number) => boolean
type TArrayPredicate = (el: T, i?: number) => boolean
type TArrayPredicate = (el:T, i?: number) => boolean
class X { foo:string }
class X { foo: string }
class X { foo:?string }
class X { foo: ?string }
class X { static foo:number }
class X { static foo: number }
class X { static foo :number }
class X { static foo : number }
declare class X { static foo:number }
declare class X { static foo: number }
declare class X { static foo :number }
declare class X { static foo : number }
type X = { foo:string }
type X = { foo:string }
type X = { foo: string }
type X = { foo: string }
type X = { foo?:string }
type X = { foo?: string }
type X = { foo?:?string }
type X = { foo?: ?string }
type Foo = { barType:(string | () => void) }
type Foo = { barType:(((string | () => void))) }
type Foo = { barType: (string | () => void) }
type Foo = { barType: (string | () => void) }
type Foo = { barType: ((string | () => void)) }
type X = { get:() => A; }
type X = { get:<X>() => A; }
type X = { get: () => A; }
type X = { get: <X>() => A; }
type X = { get: () => A; }
type X = { get: <X>() => A; }
The following patterns are not considered problems:
(foo) => {}
(foo: string) => {}
(foo: (string|number)) => {}
(foo:string) => {}
(foo: string) => {}
(foo:(() => void)) => {}
(foo: (() => void)) => {}
({ lorem, ipsum, dolor }: SomeType) => {}
(foo: { a: string, b: number }) => {}
({ a, b }: ?{ a: string, b: number }) => {}
([ a, b ]: string[]) => {}
(i?: number) => {}
(i?:number) => {}
():Object => {}
(): Object => {}
():(number | string) => {}
(): (number | string) => {}
():number|string => {}
(): number|string => {}
():(() => void) => {}
(): (() => void) => {}
():( () => void ) => {}
(): ( () => void ) => {}
(): { a: number, b: string } => {}
() :{ a:number, b:string } => {}
function x(foo: string) {}
class Foo { constructor(foo: string) {} }
function x(foo:string) {}
class Foo { constructor(foo:string) {} }
async function foo({ lorem, ipsum, dolor }: SomeType) {}
function x({ a, b }: { a: string, b: number }) {}
function x(i?: number) {}
function x(i?:number) {}
type X = (foo: number) => string;
type X = (foo : number) => string;
type X = (foo: ?number) => string;
type X = (foo? : ?number) => string;
type X = (foo: ?{ x: number }) => string;
type X = (foo:number) => string;
type X = (foo:?{ x:number }) => string;
type X = (foo: (number)) => string
type X = (foo: ((number))) => string
type X = (foo:((number))) => string
type X = ?(foo: ((number))) => string
type X = ?(foo:((number))) => string
type TArrayPredicate = (el: T, i?: number) => boolean
type TArrayPredicate = (el:T, i?:number) => boolean
class Foo { bar }
class Foo { bar = 3 }
class Foo { bar: string }
class Foo { bar: ?string }
class Foo { bar:string }
class Foo { bar:?string }
class X { static foo : number }
class X { static foo :number }
declare class X { static foo : number }
declare class X { static foo :number }
type X = { foo: string }
type X = { foo:string }
type X = { foo?: string }
type X = { foo?: ?string }
type X = { foo?:?string }
type Foo = { barType: (string | () => void) }
type Foo = { barType: ((string | () => void)) }
type Foo = { barType:(string | () => void) }
type Foo = { barType:((string | () => void)) }
type X = { get(): A; }
type X = { get<X>(): A; }
type X = { get(): A; }
type X = { get<X>(): A; }
type X = { get: () => A; }
type X = { get: <X>() => A; }
type X = { get:() => A; }
type X = { get:<X>() => A; }
space-before-generic-bracket
The --fix
option on the command line automatically fixes problems reported by this rule.
Enforces consistent spacing before the opening <
of generic type annotation parameters.
This rule takes one argument. If it is 'never'
then a problem is raised when there is a space before the <
. If it is 'always'
then a problem is raised when there is no space before the <
.
The default value is 'never'
.
The following patterns are considered problems:
type X = Promise <string>
type X = Promise <string>
type X = Promise <string>
type X = Promise<string>
type X = Promise <string>
The following patterns are not considered problems:
type X = Promise<string>
type X = Promise <string>
space-before-type-colon
The --fix
option on the command line automatically fixes problems reported by this rule.
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) => {}
(foo : string) => {}
(foo?: string) => {}
(foo ? : string) => {}
(foo ?: string) => {}
({ lorem, ipsum, dolor } : SomeType) => {}
(foo : { a: string, b: number }) => {}
({ a, b } : { a: string, b: number }) => {}
([ a, b ] : string[]) => {}
function x(foo : string) {}
function x(foo: string) {}
var x = function (foo : string) {}
var x = function (foo: string) {}
class Foo { constructor(foo : string ) {} }
class Foo { constructor(foo: string ) {} }
async function foo({ lorem, ipsum, dolor } : SomeType) {}
type X = (foo :string) => string;
type X = (foo:string) => string;
type X = (foo :string) => string;
type X = (foo? :string) => string;
type X = (foo? :string) => string;
type X = (foo?:string) => string;
type X = (foo? :?string) => string;
class X { foo :string }
class X { foo: string }
class X { foo :?string }
class X { foo: ?string }
class X { static foo : number }
class X { static foo :number }
class X { static foo: number }
class X { static foo:number }
declare class Foo { static bar :number; }
declare class Foo { static bar : number; }
declare class Foo { static bar:number; }
declare class Foo { static bar: number; }
type X = { foo : string }
type X = { foo : string }
type X = { foo: string }
type X = { foo : string }
type X = { foo? : string }
type X = { foo?: string }
type X = { foo? : string }
type X = { foo ?: string }
The following patterns are not considered problems:
(foo) => {}
(foo: string) => {}
(foo?: string) => {}
(foo ?: string) => {}
(foo: string) => {}
(foo : string) => {}
(foo? : string) => {}
(foo ? : string) => {}
(foo ? : string) => {}
({ lorem, ipsum, dolor }: SomeType) => {}
(foo: { a: string, b: number }) => {}
({ a, b }: ?{ a: string, b: number }) => {}
(): { a: number, b: string } => {}
() : { a : number, b : string } => {}
([ a, b ]: string[]) => {}
function x(foo: string) {}
function x(foo : string) {}
var x = function (foo: string) {}
var x = function (foo : string) {}
class X { foo({ bar }: Props = this.props) {} }
class Foo { constructor(foo: string ) {} }
class Foo { constructor(foo : string ) {} }
async function foo({ lorem, ipsum, dolor }: SomeType) {}
function x({ a, b }: { a: string, b: number }) {}
type X = (foo:string) => number;
type X = (foo: string) => number;
type X = (foo: ?string) => number;
type X = (foo?: string) => number;
type X = (foo?: ?string) => number;
type X = (foo ?: string) => number;
type X = (foo? : string) => number
type X = (foo? : ?string) => number
class Foo { bar }
class Foo { bar = 3 }
class Foo { bar: string }
class Foo { bar: ?string }
class Foo { bar:?string }
class Foo { bar : string }
class X { static foo:number }
class X { static foo: number }
class X { static foo :number }
class X { static foo : number }
declare class Foo { static bar:number; }
declare class Foo { static bar :number; }
declare class Foo { static bar: number; }
declare class Foo { static bar : number; }
type X = { foo: string }
type X = { foo : string }
type X = { foo?: string }
type X = { foo ?: string }
type X = { 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 = {};
type FooType = {};
The following patterns are not considered problems:
type FooType = {};
type foo = {};
union-intersection-spacing
The --fix
option on the command line automatically fixes problems reported by this rule.
Enforces consistent spacing around union and intersection type separators (|
and &
).
This rule takes one argument. If it is 'always'
then a problem is raised when there is no space around the separator. If it is 'never'
then a problem is raised when there is a space around the separator.
The default value is 'always'
.
The following patterns are considered problems:
type X = string| number;
type X = string| number;
type X = string |number;
type X = string|number;
type X = {x: string}|{y: number};
type X = string | number |boolean;
type X = string|number|boolean;
type X = (string)| number;
type X = ((string))|(number | foo);
type X = string |number;
type X = string| number;
type X = string& number;
type X = string& number;
type X = string &number;
type X = {x: string}&{y: number};
type X = string&number;
type X = string & number &boolean;
type X = string&number&boolean;
type X = (string)& number;
type X = ((string))&(number & foo);
type X = string &number;
type X = string& number;
The following patterns are not considered problems:
type X = string | number;
type X = string | number | boolean;
type X = (string) | number;
type X = ((string)) | (number | foo);
type X = string|number
type X =
| string
| number
function x() {
type X =
| string
| number
}
type X = string & number;
type X = string & number & boolean;
type X = (string) & number;
type X = ((string)) & (number & foo);
type X = string&number
type X =
& string
& number
function x() {
type X =
& string
& number
}
use-flow-type
Marks Flow type alias declarations as used.
Used to suppress no-unused-vars
errors that are triggered by type aliases.
The following patterns are not considered problems:
declare class A {}
declare function A(): Y
declare module A {}
declare module A { declare var a: Y }
declare var A: Y
import type A from "a"; (function<T: A>(): T {})
(function<T: A>(): T {}); import type A from "a"
import type {A} from "a"; (function<T: A>(): T {})
(function<T: A>(): T {}); import type {A} from "a"
(function<T: A>(): T {}); import type {a as A} from "a"
type A = {}; function x<Y: A>(i: Y) { i }; x()
function x<Y: A>(i: Y) { i }; type A = {}; x()
type A = {}; function x<Y: A.B.C>(i: Y) { i }; x()
function x<Y: A.B.C>(i: Y) { i }; type A = {}; x()
valid-syntax
Checks for simple Flow syntax errors.
The following patterns are considered problems:
function x(foo = "1": string) {}
function x(foo = bar(): Type, baz = []: []) {}
The following patterns are not considered problems:
function x(foo: string = "1") {}
function x(foo: Type = bar()) {}