Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Flow type linting rules for ESLint.

License

NotificationsYou must be signed in to change notification settings

gajus/eslint-plugin-flowtype

Repository files navigation

eslint-plugin-flowtype

NPM versionTravis build statusjs-canonical-style

Flow type linting rules for ESLint.

Installation

npm install eslint --save-devnpm install @babel/eslint-parser --save-devnpm install eslint-plugin-flowtype --save-dev

Configuration

  1. Setparser property to@babel/eslint-parser.
  2. Addplugins section and specifyeslint-plugin-flowtype as a plugin.
  3. Enable rules.
{"parser":"@babel/eslint-parser","plugins": ["flowtype"  ],"rules": {"flowtype/boolean-style": [2,"boolean"    ],"flowtype/define-flow-type":1,"flowtype/delimiter-dangle": [2,"never"    ],"flowtype/generic-spacing": [2,"never"    ],"flowtype/interface-id-match": [2,"^([A-Z][a-z0-9]+)+Type$"    ],"flowtype/no-mixed":2,"flowtype/no-primitive-constructor-types":2,"flowtype/no-types-missing-file-annotation":2,"flowtype/no-weak-types":2,"flowtype/object-type-delimiter": [2,"comma"    ],"flowtype/require-parameter-type":2,"flowtype/require-readonly-react-props":0,"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 arecommended 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"  ]}

SeeESLint documentation for more information about extending configuration files.

Community maintained configurations

The following are third-party submitted/ maintained configurations ofeslint-plugin-flowtype:

Settings

onlyFilesWithFlowAnnotation

Whentrue, only checks files with a@flow annotation in the first comment.

{"settings":{"flowtype":{"onlyFilesWithFlowAnnotation":true}}}

Rules

array-style-complex-type

The--fix option on the command line automatically fixes problems reported by this rule.

Enforces a particular annotation style of complex types.

Type is considered complex in these cases:

This rule takes one argument.

If it is'verbose' then a problem is raised when usingType[] instead ofArray<Type>.

If it is'shorthand' then a problem is raised when usingArray<Type> instead ofType[].

The default value is'verbose'.

The following patterns are considered problems:

typeX=(?string)[]// Message: Use "Array<?string>", not "(?string)[]"// Options: ["verbose"]typeX=(?string)[]// Message: Use "Array<?string>", not "(?string)[]"// Options: ["shorthand"]typeX=Array<?string>// Message: Use "(?string)[]", not "Array<?string>"// Options: ["shorthand"]typeX=Array<{foo:string}>// Message: Use "{foo: string}[]", not "Array<{foo: string}>"typeX=(string|number)[]// Message: Use "Array<string | number>", not "(string | number)[]"typeX=(string&number)[]// Message: Use "Array<string & number>", not "(string & number)[]"typeX=[string,number][]// Message: Use "Array<[string, number]>", not "[string, number][]"typeX={foo:string}[]// Message: Use "Array<{foo: string}>", not "{foo: string}[]"typeX=(string=>number)[]// Message: Use "Array<string => number>", not "(string => number)[]"typeX={foo:string,bar:number}[]// Message: Use "Array<{ foo: string, bar: number }>", not "{ foo: string, bar: number }[]"typeX={foo:string,bar:number,quo:boolean,hey:Date}[]// Message: Use "Array<Type>", not "Type[]"

The following patterns are not considered problems:

typeX=Array<?string>// Options: ["verbose"]typeX=Array<?string>// Options: ["shorthand"]typeX=(?string)[]// Options: ["shorthand"]typeX=Array<string>// Options: ["shorthand"]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeX=Array<?string>

array-style-simple-type

The--fix option on the command line automatically fixes problems reported by this rule.

Enforces a particular array type annotation style of simple types.

Type is considered simple in these cases:

This rule takes one argument.

If it is'verbose' then a problem is raised when usingType[] instead ofArray<Type>.

If it is'shorthand' then a problem is raised when usingArray<Type> instead ofType[].

The default value is'verbose'.

The following patterns are considered problems:

typeX=string[]// Message: Use "Array<string>", not "string[]"// Options: ["verbose"]typeX=string[]// Message: Use "Array<string>", not "string[]"// Options: ["shorthand"]typeX=Array<string>// Message: Use "string[]", not "Array<string>"typeX=Date[]// Message: Use "Array<Date>", not "Date[]"typeX=Promise<string>[]// Message: Use "Array<Promise<string>>", not "Promise<string>[]"typeX=$Keys<{foo:string}>[]// Message: Use "Array<$Keys<{foo: string}>>", not "$Keys<{foo: string}>[]"typeX=any[]// Message: Use "Array<any>", not "any[]"typeX=mixed[]// Message: Use "Array<mixed>", not "mixed[]"typeX=void[]// Message: Use "Array<void>", not "void[]"typeX=null[]// Message: Use "Array<null>", not "null[]"typeX=Promise<{foo:string,bar:number}>[]// Message: Use "Array<Promise<{ foo: string, bar: number }>>", not "Promise<{ foo: string, bar: number }>[]"typeX=Promise<{foo:string,bar:number,quo:boolean}>[]// Message: Use "Array<Type>", not "Type[]"

The following patterns are not considered problems:

typeX=Array<string>// Options: ["verbose"]typeX=Array<string>// Options: ["shorthand"]typeX=string[]typeX=Array<Array<string>>// Options: ["verbose"]typeX=(?string)[]// Options: ["verbose"]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeX=string[]typeX=ArraytypeX=typeofArray

arrow-parens

The--fix option on the command line automatically fixes problems reported by this rule.

Enforces the consistent use of parentheses in arrow functions.

This rule has a string option and an object one.

String options are:

  • "always" (default) requires parens around arguments in all cases.
  • "as-needed" enforces no braces where they can be omitted.

Object properties for variants of the"as-needed" option:

  • "requireForBlockBody": true modifies the as-needed rule in order to require parens if the function body is in an instructions block (surrounded by braces).

The following patterns are considered problems:

a=>{}// Message: undefineda=>a// Message: undefineda=>{}// Message: undefineda.then(foo=>{});// Message: undefineda.then(foo=>a);// Message: undefineda(foo=>{if(true){};});// Message: undefineda(asyncfoo=>{if(true){};});// Message: undefined// Options: ["as-needed"](a)=>a// Message: undefined// Options: ["as-needed"](a,)=>a// Message: undefined// Options: ["as-needed"]async(a)=>a// Message: undefined// Options: ["as-needed"]async(a)=>a// Message: undefined// Options: ["as-needed",{"requireForBlockBody":true}]a=>{}// Message: undefined// Options: ["as-needed",{"requireForBlockBody":true}](a)=>a// Message: undefined// Options: ["as-needed",{"requireForBlockBody":true}]asynca=>{}// Message: undefined// Options: ["as-needed",{"requireForBlockBody":true}]async(a)=>a// Message: undefined// Options: ["as-needed",{"requireForBlockBody":true}]async(a)=>a// Message: undefined

The following patterns are not considered problems:

()=>{}(a)=>{}(a)=>a(a)=>{}a.then((foo)=>{});a.then((foo)=>{if(true){};});a.then(async(foo)=>{if(true){};});// Options: ["always"]()=>{}// Options: ["always"](a)=>{}// Options: ["always"](a)=>a// Options: ["always"](a)=>{}// Options: ["always"]a.then((foo)=>{});// Options: ["always"]a.then((foo)=>{if(true){};});// Options: ["always"]a.then(async(foo)=>{if(true){};});// Options: ["as-needed"]()=>{}// Options: ["as-needed"]a=>{}// Options: ["as-needed"]a=>a// Options: ["as-needed"]([a,b])=>{}// Options: ["as-needed"]({ a, b})=>{}// Options: ["as-needed"](a=10)=>{}// Options: ["as-needed"](...a)=>a[0]// Options: ["as-needed"](a,b)=>{}// Options: ["as-needed"]async([a,b])=>{}// Options: ["as-needed"]async(a,b)=>{}// Options: ["as-needed"](a:T)=>a// Options: ["as-needed"](a):T=>a// Options: ["as-needed",{"requireForBlockBody":true}]()=>{}// Options: ["as-needed",{"requireForBlockBody":true}]a=>a// Options: ["as-needed",{"requireForBlockBody":true}]([a,b])=>{}// Options: ["as-needed",{"requireForBlockBody":true}]([a,b])=>a// Options: ["as-needed",{"requireForBlockBody":true}]({ a, b})=>{}// Options: ["as-needed",{"requireForBlockBody":true}]({ a, b})=>a+b// Options: ["as-needed",{"requireForBlockBody":true}](a=10)=>{}// Options: ["as-needed",{"requireForBlockBody":true}](...a)=>a[0]// Options: ["as-needed",{"requireForBlockBody":true}](a,b)=>{}// Options: ["as-needed",{"requireForBlockBody":true}]a=>({})// Options: ["as-needed",{"requireForBlockBody":true}]asynca=>({})// Options: ["as-needed",{"requireForBlockBody":true}]asynca=>a// Options: ["as-needed",{"requireForBlockBody":true}](a:T)=>a// Options: ["as-needed",{"requireForBlockBody":true}](a):T=>a// Options: ["always",{"requireForBlockBody":true}]<T>(a:T)=>a// Options: ["as-needed",{"requireForBlockBody":false}]<T>(a:T)=>{returna;}// Options: ["always",{"requireForBlockBody":true}]<T>(a:T)=>{returna;}// Options: ["as-needed",{"requireForBlockBody":true}]<T>(a:T)=>{returna;}// Options: ["as-needed",{"requireForBlockBody":true}](a):%checks=>typeofa==="number"

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 usingbool instead ofboolean.

If it is'bool' then a problem is raised when usingboolean instead ofbool.

The default value is'boolean'.

The following patterns are considered problems:

typeX=bool// Message: Use "boolean", not "bool"// Options: ["boolean"]typeX=bool// Message: Use "boolean", not "bool"// Options: ["bool"]typeX=boolean// Message: Use "bool", not "boolean"

The following patterns are not considered problems:

typeX=boolean// Options: ["boolean"]typeX=boolean// Options: ["bool"]typeX=bool// Options: ["boolean"]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeX=bool

define-flow-type

Marks Flow type identifiers as defined.

Used to suppressno-undef reporting of type identifiers.

The following patterns are not considered problems:

vara:AType// Additional rules: {"no-undef":2}vara:AType;varb:AType// Additional rules: {"no-undef":2}vara;(a:AType)// Additional rules: {"no-undef":2}vara:AType<BType>// Additional rules:{"no-undef":2}type A = AType// Additional rules:{"no-undef":2}declare type A = number// Additional rules:{"no-undef":2}opaque type A = AType// Additional rules:{"no-undef":2}function f(a: AType){}// Additional rules:{"no-undef":2}function f(a: AType.a){}// Additional rules:{"no-undef":2}function f(a: AType.a.b){}// Additional rules:{"no-undef":2}function f(a): AType{}; var a: AType// Additional rules:{"no-undef":2}function f(a): AType{}// Additional rules:{"no-undef":2}class C{a:AType}// Additional rules:{"no-undef":2}class C{a:AType.a}// Additional rules:{"no-undef":2}class C{a:AType.a.b}// Additional rules:{"no-undef":2}class C implements AType{}// Additional rules:{"no-undef":2}declare interface A{}// Additional rules:{"no-undef":2}({a:({b(){}}:AType)})// Additional rules:{"no-undef":2}type X ={Y<AType>():BType}// Additional rules:{"no-undef":2}// Settings:{"flowtype":{"onlyFilesWithFlowAnnotation":true}}/*** Copyright 2019 no corp* @flow*/type Foo = $ReadOnly<{}>// Additional rules: {"no-undef":2}vara:AType// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}vara:AType;varb:AType// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}vara;(a:AType)// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}vara:AType<BType>// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}type A = AType// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}declare type A = number// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}opaque type A = AType// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}function f(a: AType){}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}function f(a: AType.a){}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}function f(a: AType.a.b){}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}function f(a): AType{}; var a: AType// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}function f(a): AType{}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}class C{a:AType}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}class C{a:AType.a}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}class C{a:AType.a.b}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}class C implements AType{}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}declare interface A{}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}({a:({b(){}}:AType)})// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}type X ={Y<AType>():BType}// Additional rules:{"no-undef":2,"no-use-before-define":[2,"nofunc"]}// Settings:{"flowtype":{"onlyFilesWithFlowAnnotation":true}}/*** Copyright 2019 no corp* @flow*/type Foo = $ReadOnly<{}>// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}

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 three arguments where the possible values are the same as ESLint's defaultcomma-dangle rule:

  1. The first argument is for Object and Tuple annotations. The default value is'never'.
  2. The second argument is used for Interface annotations. This defaults to the value of the first argument.
  3. The third argument is used for inexact object notation (trailing...). The default value is'never'.

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 thereis 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 following patterns are considered problems:

typeX={foo:string,}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={foo:string,}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={foo:string;}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={foo:string,}// Message: Unexpected trailing delimiter// Options: ["always"]typeX={foo:string}// Message: Missing trailing delimiter// Options: ["always"]typeX={foo:string}// Message: Missing trailing delimiter// Options: ["always-multiline"]typeX={foo:string,}// Message: Unexpected trailing delimiter// Options: ["always-multiline"]typeX={foo:string}// Message: Missing trailing delimiter// Options: ["only-multiline"]typeX={foo:string;}// Message: Unexpected trailing delimiter// Options: ["always","never"]interfaceX{ foo:string;}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={[key:string]:number,}// Message: Unexpected trailing delimiter// Options: ["always"]typeX={[key:string]:number}// Message: Missing trailing delimiter// Options: ["always-multiline"]typeX={[key:string]:number,}// Message: Unexpected trailing delimiter// Options: ["always-multiline"]typeX={[key:string]:number}// Message: Missing trailing delimiter// Options: ["only-multiline"]typeX={[key:string]:number;}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={[key:string]:number,foo:string,}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={[key:string]:number,foo:string,}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={[key:string]:number,aReallyLongPropertyNameHere:string,}// Message: Unexpected trailing delimiter// Options: ["always"]typeX={[key:string]:number,foo:string}// Message: Missing trailing delimiter// Options: ["always"]typeX={[key:string]:number;foo:string}// Message: Missing trailing delimiter// Options: ["always-multiline"]typeX={[key:string]:number,foo:string,}// Message: Unexpected trailing delimiter// Options: ["always-multiline"]typeX={[key:string]:number,foo:string}// Message: Missing trailing delimiter// Options: ["only-multiline"]typeX={[key:string]:number,foo:string,}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={foo:string,[key:string]:number,}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={foo:string,[key:string]:number,}// Message: Unexpected trailing delimiter// Options: ["never"]typeX={aReallyLongPropertyNameHere:string,[key:string]:number,}// Message: Unexpected trailing delimiter// Options: ["always"]typeX={foo:string,[key:string]:number}// Message: Missing trailing delimiter// Options: ["always"]typeX={foo:string;[key:string]:number}// Message: Missing trailing delimiter// Options: ["always-multiline"]typeX={foo:string,[key:string]:number;}// Message: Unexpected trailing delimiter// Options: ["always-multiline"]typeX={foo:string,[key:string]:number}// Message: Missing trailing delimiter// Options: ["only-multiline"]typeX={foo:string,[key:string]:number;}// Message: Unexpected trailing delimitertypeX={ ...,}// Message: Unexpected trailing delimitertypeX={ ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={ ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={ ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","always"]typeX={ ...}// Message: Missing trailing delimiter// Options: ["never","never","always-multiline"]typeX={ ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","always-multiline"]typeX={ ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","only-multiline"]typeX={ ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","only-multiline"]typeX={ ...;}// Message: Unexpected trailing delimitertypeX={...,}// Message: Unexpected trailing delimitertypeX={...;}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={...,}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={...;}// Message: Unexpected trailing delimiter// Options: ["never","never","always"]typeX={...}// Message: Missing trailing delimiter// Options: ["never","never","always-multiline"]typeX={...}// Message: Missing trailing delimitertypeX={foo:string, ...,}// Message: Unexpected trailing delimitertypeX={foo:string; ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={foo:string, ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={foo:string; ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","always"]typeX={foo:string, ...}// Message: Missing trailing delimiter// Options: ["never","never","always-multiline"]typeX={foo:string, ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","always-multiline"]typeX={foo:string; ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","only-multiline"]typeX={foo:string, ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","only-multiline"]typeX={foo:string; ...;}// Message: Unexpected trailing delimitertypeX={foo:string,...,}// Message: Unexpected trailing delimitertypeX={foo:string;...;}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={foo:string,...,}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={foo:string;...;}// Message: Unexpected trailing delimiter// Options: ["never","never","always"]typeX={foo:string,...}// Message: Missing trailing delimiter// Options: ["never","never","always-multiline"]typeX={foo:string,...}// Message: Missing trailing delimitertypeX={[key:string]:number, ...,}// Message: Unexpected trailing delimitertypeX={[key:string]:number; ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={[key:string]:number, ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={[key:string]:number; ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","always"]typeX={[key:string]:number, ...}// Message: Missing trailing delimiter// Options: ["never","never","always-multiline"]typeX={[key:string]:number, ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","always-multiline"]typeX={[key:string]:number; ...;}// Message: Unexpected trailing delimiter// Options: ["never","never","only-multiline"]typeX={[key:string]:number, ...,}// Message: Unexpected trailing delimiter// Options: ["never","never","only-multiline"]typeX={[key:string]:number; ...;}// Message: Unexpected trailing delimitertypeX={[key:string]:number,...,}// Message: Unexpected trailing delimitertypeX={[key:string]:number;...;}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={[key:string]:number,...,}// Message: Unexpected trailing delimiter// Options: ["never","never","never"]typeX={[key:string]:number;...;}// Message: Unexpected trailing delimiter// Options: ["never","never","always"]typeX={[key:string]:number,...}// Message: Missing trailing delimiter// Options: ["never","never","always-multiline"]typeX={[key:string]:number,...}// Message: Missing trailing delimitertypeX=[string,number,]// Message: Unexpected trailing delimiter// Options: ["never"]typeX=[string,number,]// Message: Unexpected trailing delimiter// Options: ["never"]typeX=[string,number,]// Message: Unexpected trailing delimiter// Options: ["always"]typeX=[string,number]// Message: Missing trailing delimiter// Options: ["always"]typeX=[string,number]// Message: Missing trailing delimiter// Options: ["always-multiline"]typeX=[string,number,]// Message: Unexpected trailing delimiter// Options: ["always-multiline"]typeX=[foo,string]// Message: Missing trailing delimiter// Options: ["only-multiline"]typeX=[number,string,]// Message: Unexpected trailing delimiter

The following patterns are not considered problems:

typeX={foo:string}// Options: ["never"]typeX={foo:string}// Options: ["always"]typeX={foo:string,}// Options: ["always"]typeX={foo:string;}// Options: ["never"]typeX={foo:string}// Options: ["always"]typeX={foo:string,}// Options: ["always-multiline"]typeX={foo:string}// Options: ["always-multiline"]typeX={foo:string,}// Options: ["always-multiline"]typeX={foo:string;}// Options: ["only-multiline"]typeX={foo:string}// Options: ["only-multiline"]typeX={foo:string}// Options: ["only-multiline"]typeX={foo:string,}// Options: ["only-multiline"]typeX={foo:string;}// Options: ["never","always"]interfaceX{ foo:string;}// Options: ["never"]typeX={}// Options: ["always"]typeX={}// Options: ["always-multiline"]typeX={}// Options: ["only-multiline"]typeX={}// Options: ["never"]typeX={[key:string]:number}// Options: ["always"]typeX={[key:string]:number,}// Options: ["always"]typeX={[key:string]:number;}// Options: ["always-multiline"]typeX={[key:string]:number}// Options: ["always-multiline"]typeX={[key:string]:number,}// Options: ["only-multiline"]typeX={[key:string]:number,}// Options: ["only-multiline"]typeX={[key:string]:number}// Options: ["only-multiline"]typeX={[key:string]:number}// Options: ["never"]typeX={[key:string]:number,foo:string}// Options: ["always"]typeX={[key:string]:number,foo:string,}// Options: ["always"]typeX={[key:string]:number; foo:string;}// Options: ["always-multiline"]typeX={[key:string]:number,foo:string}// Options: ["always-multiline"]typeX={[key:string]:number,foo:string,}// Options: ["only-multiline"]typeX={[key:string]:number,foo:string,}// Options: ["only-multiline"]typeX={[key:string]:number;foo:string}// Options: ["only-multiline"]typeX={[key:string]:number,foo:string}// Options: ["never"]typeX={foo:string,[key:string]:number}// Options: ["always"]typeX={foo:string,[key:string]:number,}// Options: ["always"]typeX={foo:string;[key:string]:number;}// Options: ["always-multiline"]typeX={foo:string,[key:string]:number}// Options: ["always-multiline"]typeX={foo:string,[key:string]:number,}// Options: ["only-multiline"]typeX={foo:string,[key:string]:number,}// Options: ["only-multiline"]typeX={foo:string;[key:string]:number}// Options: ["only-multiline"]typeX={foo:string,[key:string]:number}typeX={ ...}// Options: ["never","never","never"]typeX={ ...}// Options: ["never","never","always"]typeX={ ...,}// Options: ["never","never","always-multiline"]typeX={ ...}// Options: ["never","never","only-multiline"]typeX={ ...}typeX={...}// Options: ["never","never","never"]typeX={...}// Options: ["never","never","always"]typeX={...,}// Options: ["never","never","always"]typeX={...;}// Options: ["never","never","always-multiline"]typeX={...,}// Options: ["never","never","always-multiline"]typeX={...;}// Options: ["never","never","only-multiline"]typeX={...}// Options: ["never","never","only-multiline"]typeX={...,}// Options: ["never","never","only-multiline"]typeX={...;}typeX={foo:string, ...}// Options: ["never","never","never"]typeX={foo:string, ...}// Options: ["never","never","always"]typeX={foo:string, ...,}// Options: ["never","never","always"]typeX={foo:string; ...;}// Options: ["never","never","always-multiline"]typeX={foo:string, ...}// Options: ["never","never","only-multiline"]typeX={foo:string, ...}typeX={foo:string,...}// Options: ["never","never","never"]typeX={foo:string,...}// Options: ["never","never","always"]typeX={foo:string,...,}// Options: ["never","never","always"]typeX={foo:string;...;}// Options: ["never","never","always-multiline"]typeX={foo:string,...,}// Options: ["never","never","always-multiline"]typeX={foo:string;...;}// Options: ["never","never","only-multiline"]typeX={foo:string,...}// Options: ["never","never","only-multiline"]typeX={foo:string,...,}// Options: ["never","never","only-multiline"]typeX={foo:string,...;}// Options: ["never","never","never"]typeX={[key:string]:number, ...}// Options: ["never","never","always"]typeX={[key:string]:number, ...,}// Options: ["never","never","always"]typeX={[key:string]:number; ...;}// Options: ["never","never","always-multiline"]typeX={[key:string]:number, ...}// Options: ["never","never","only-multiline"]typeX={[key:string]:number, ...}// Options: ["never","never","never"]typeX={[key:string]:number,...}// Options: ["never","never","always"]typeX={[key:string]:number,...,}// Options: ["never","never","always"]typeX={[key:string]:number;...;}// Options: ["never","never","always-multiline"]typeX={[key:string]:number,...,}// Options: ["never","never","always-multiline"]typeX={[key:string]:number;...;}// Options: ["never","never","only-multiline"]typeX={[key:string]:number,...}// Options: ["never","never","only-multiline"]typeX={[key:string]:number,...,}// Options: ["never","never","only-multiline"]typeX={[key:string]:number;...;}typeX=[string,number]// Options: ["never"]typeX=[string,number]// Options: ["never"]typeX=[string,number]// Options: ["always"]typeX=[string,number,]// Options: ["always"]typeX=[string,number,]// Options: ["always-multiline"]typeX=[foo,string]// Options: ["always-multiline"]typeX=[foo,string,]// Options: ["only-multiline"]typeX=[number,string]// Options: ["only-multiline"]typeX=[number,string]// Options: ["only-multiline"]typeX=[number,string,]// Options: ["never"]typeX=[]// Options: ["always"]typeX=[]// Options: ["always-multiline"]typeX=[]// Options: ["only-multiline"]typeX=[]

enforce-line-break

This rule enforces line breaks between type definitions.

The following patterns are considered problems:

typebaz=6;consthi=2;// Message: New line required below type declarationconstfoo=6;typehi=2;// Message: New line required above type declarationconstsom="jes";// a commenttypefed="hed";// Message: New line required above type declarationtypesom="jes";// a commentconstfed="hed";// Message: New line required below type declarationtypehello=34;constsom="jes";typefed="hed";// Message: New line required below type declaration// Message: New line required above type declarationconsta=5;exporttypehello=34;// Message: New line required above type declarationconsta=5;// a commentexporttypehello=34;// Message: New line required above type declarationconsta=5;/** * a jsdoc block */typehello=34;// Message: New line required above type declaration

The following patterns are not considered problems:

typegjs=6;typegjs=6;typehi=2;typeX=4;constred="serpent";console.log("hello");// number or stringtypeY=string|number;// resting + sleeptypesnooze="dreaming"|"";typeProps={accountBalance:string|number,accountNumber:string|number,};constx=4;consty=489;// Some CommenttypeProps={accountBalance:string|number,accountNumber:string|number,};typeRoadT="grass"|"gravel"|"cement";//@flowtypeA=string

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:

typeX=Promise<string>// Message: There must be no space at start of "Promise" generic type annotation// Options: ["never"]typeX=Promise<string>// Message: There must be no space at start of "Promise" generic type annotationtypeX=FooBar<string>// Message: There must be no space at end of "FooBar" generic type annotationtypeX=Promise<string>// Message: There must be no space at start of "Promise" generic type annotation// Message: There must be no space at end of "Promise" generic type annotationtypeX=Promise<(foo),bar,(((baz)))>// Message: There must be no space at start of "Promise" generic type annotation// Message: There must be no space at end of "Promise" generic type annotation// Options: ["always"]typeX=Promise<string>// Message: There must be a space at start of "Promise" generic type annotation// Options: ["always"]typeX=FooBar<string>// Message: There must be a space at end of "FooBar" generic type annotation// Options: ["always"]typeX=Promise<string>// Message: There must be a space at start of "Promise" generic type annotation// Message: There must be a space at end of "Promise" generic type annotation// Options: ["always"]typeX=Promise<(foo),bar,(((baz)))>// Message: There must be a space at start of "Promise" generic type annotation// Message: There must be a space at end of "Promise" generic type annotation// Options: ["always"]typeX=FooBar<string>// Message: There must be one space at start of "FooBar" generic type annotation// Options: ["always"]typeX=FooBar<string>// Message: There must be one space at end of "FooBar" generic type annotation// Options: ["always"]typeX=Promise<(foo),bar,(((baz)))>// Message: There must be one space at start of "Promise" generic type annotation// Message: There must be one space at end of "Promise" generic type annotation

The following patterns are not considered problems:

typeX=Promise<string>typeX=Promise<(string)>typeX=Promise<(foo),bar,(((baz)))>typeX=Promise<(foo),bar,(((baz)))>typeX=Promise<(foo),bar,(((baz)))>// Options: ["always"]typeX=Promise<string>// Options: ["always"]typeX=Promise<(string)>// Options: ["always"]typeX=Promise<(foo),bar,(((baz)))>

interface-id-match

Enforces a consistent naming pattern for interfaces.

Options

This rule requires a text RegExp:

{"rules":{"flowtype/interface-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:

interfacefoo{};// Message: Interface identifier 'foo' does not match pattern '/^([A-Z][a-z0-9]*)+Type$/u'.// Options: ["^foo$"]interfaceFooType{};// Message: Interface identifier 'FooType' does not match pattern '/^foo$/u'.

The following patterns are not considered problems:

interfaceFooType{};// Options: ["^foo$"]interfacefoo{};// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}interfacefoo{};

newline-after-flow-annotation

This rule requires an empty line after the Flow annotation.

Options

The rule has a string option:

  • "always" (default): Enforces that@flow annotations be followed by an empty line, separated by newline (LF)
  • "always-windows": Identical to "always", but will use a CRLF when autofixing
  • "never": Enforces that@flow annotations are not followed by empty lines
{"rules":{"flowtype/newline-after-flow-annotation":[2,"always"]}}

The following patterns are considered problems:

//@flowimportFoofrom'./foo';// Message: Expected newline after flow annotation// Options: ["always"]//@flowimportFoofrom'./foo';// Message: Expected newline after flow annotation// Options: ["always-windows"]//@flowimportFoofrom'./foo';// Message: Expected newline after flow annotation// Options: ["never"]//@flow// Message: Expected no newline after flow annotation

The following patterns are not considered problems:

// Options: ["always"]//@flowimportFoofrom'./foo';// Options: ["always-windows"]//@flowimportFoofrom'./foo';// Options: ["never"]//@flowimportFoofrom'./foo';

no-dupe-keys

Checks for duplicate properties in Object annotations.

This rule mirrors ESLint'sno-dupe-keys rule.

{"rules":{"flowtype/no-dupe-keys":2}}

The following patterns are considered problems:

typef={a:number,b:string,a:number}// Message: Duplicate property.typef={a:number,b:string,a:string}// Message: Duplicate property.typef={get(key:"a"):string,get(key:"a"):string}// Message: Duplicate property.typef={get(key:1):string,get(key:1):string}// Message: Duplicate property.typef={get(key:1.1):string,get(key:1.1):string}// Message: Duplicate property.typef={get(key:true):string,get(key:true):string}// Message: Duplicate property.typef={get(key:{a:1}):string,get(key:{a:1}):string}// Message: Duplicate property.vara="a";typef={get(key:a):string,get(key:a):string}// Message: Duplicate property.varb=1;typef={get(key:b):string,get(key:b):string}// Message: Duplicate property.varc=true;typef={get(key:c):string,get(key:c):string}// Message: Duplicate property.vard={};typef={get(key:d):string,get(key:d):string}// Message: Duplicate property.vare=[];typef={get(key:e):string,get(key:e):string}// Message: Duplicate property.vare=[1,"a"];typef={get(key:e):string,get(key:e):string}// Message: Duplicate property.functionfn(){};typef={get(key:fn):string,get(key:fn):string}// Message: Duplicate property.

The following patterns are not considered problems:

typeFooType={a:number,b:string,c:number}// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeFooType={a:number,b:string,a:number}typef={get(key:"a"):string,get(key:"b"):string}typef={get(key:1):string,get(key:2):string}typef={get(key:1.1):string,get(key:1.2):string}typef={get(key:true):string,get(key:false):string}typef={get(key:["a",1]):string,get(key:["a",2]):string}typef={get(key:["a",["b",1]]):string,get(key:["a",["b",2]]):string}typef={a:number,b:string,c:number}typef={get(key:"a"):string,get(key:"b"):string}typef={get(key:"a"):string,get(key:"a",key2:"b"):string}typef={get(key:"a"):string,get(key:1):string}typef={get(key:{a:1}):string,get(key:{a:2}):string}vara={};varb={};typef={get(key:a):string,get(key:b):string}vara=1;varb=1;typef={get(key:a):string,get(key:b):string}typea={b:<C>(config:{ ...C,key:string}) =>C}exportinterfaceFoo{getfoo():boolean;getbar():string;}

no-duplicate-type-union-intersection-members

The--fix option on the command line automatically fixes problems reported by this rule.

Checks for duplicate members of a type union/intersection.

Options

You can disable checking intersection types usingcheckIntersections.

  • true (default) - check for duplicate members of intersection members.
  • false - do not check for duplicate members of intersection members.
{"rules":{"flowtype/no-duplicate-type-union-intersection-members":[2,{"checkIntersections":true}]}}

You can disable checking union types usingcheckUnions.

  • true (default) - check for duplicate members of union members.
  • false - do not check for duplicate members of union members.
{"rules":{"flowtype/no-duplicate-type-union-intersection-members":[2,{"checkUnions":true}]}}

The following patterns are considered problems:

typeA=1|2|3|1;// Message: Duplicate union member found "1".typeB='foo'|'bar'|'foo';// Message: Duplicate union member found "'foo'".typeC=A|B|A|B;// Message: Duplicate union member found "A".// Message: Duplicate union member found "B".typeC=A&B&A&B;// Message: Duplicate intersection member found "A".// Message: Duplicate intersection member found "B".

The following patterns are not considered problems:

typeA=1|2|3;typeB='foo'|'bar';typeC=A|B;typeC=A&B;

no-existential-type

Disallows use of the existential type (*).See more

{"rules":{"flowtype/no-existential-type":2}}

The following patterns are considered problems:

typeT=*;// Message: Unexpected use of existential type (*).typeT=U<*,*>;// Message: Unexpected use of existential type (*).// Message: Unexpected use of existential type (*).constf:(*)=>null=()=>null;// Message: Unexpected use of existential type (*).

The following patterns are not considered problems:

typeT=string|null

no-flow-fix-me-comments

Disallows$FlowFixMe comment suppressions.

This is especially useful as a warning to ensure instances of$FlowFixMe in your codebase get fixed over time.

Options

This rule takes an optional RegExp that comments a text RegExp that makes the supression valid.

{"rules":{"flowtype/no-flow-fix-me-comments":[1,"TODO\s+[0-9]+"]}}

The following patterns are considered problems:

// $FlowFixMe I am doing something evil hereconsttext='HELLO';// Message: $FlowFixMe is treated as `any` and must be fixed.// Options: ["TODO [0-9]+"]// $FlowFixMe I am doing something evil hereconsttext='HELLO';// Message: $FlowFixMe is treated as `any` and must be fixed. Fix it or match `/TODO [0-9]+/u`.// Options: ["TODO [0-9]+"]// $FlowFixMe TODO abc 47 I am doing something evil hereconsttext='HELLO';// Message: $FlowFixMe is treated as `any` and must be fixed. Fix it or match `/TODO [0-9]+/u`.// $$FlowFixMeProps I am doing something evil hereconsttext='HELLO';// Message: $FlowFixMe is treated as `any` and must be fixed.// Options: ["TODO [0-9]+"]// $FlowFixMeProps I am doing something evil hereconsttext='HELLO';// Message: $FlowFixMe is treated as `any` and must be fixed. Fix it or match `/TODO [0-9]+/u`.

The following patterns are not considered problems:

consttext='HELLO';// Options: ["TODO [0-9]+"]// $FlowFixMe TODO 48consttext='HELLO';

no-internal-flow-type

Warns against using internal Flow types such asReact$Node,React$Ref and others and suggests using public alternatives instead (React.Node,React.Ref, …).

The following patterns are considered problems:

typeX=React$AbstractComponent<Config,Instance>// Message: Type identifier 'React$AbstractComponent' is not allowed. Use 'React.AbstractComponent' instead.typeX=React$ChildrenArray<string>// Message: Type identifier 'React$ChildrenArray' is not allowed. Use 'React.ChildrenArray' instead.typeX=React$ComponentType<Props>// Message: Type identifier 'React$ComponentType' is not allowed. Use 'React.ComponentType' instead.typeX=React$Config<Prosp,DefaultProps>// Message: Type identifier 'React$Config' is not allowed. Use 'React.Config' instead.typeX=React$Element<typeofComponent>// Message: Type identifier 'React$Element' is not allowed. Use 'React.Element' instead.typeX=React$ElementConfig<typeofComponent>// Message: Type identifier 'React$ElementConfig' is not allowed. Use 'React.ElementConfig' instead.typeX=React$ElementProps<typeofComponent>// Message: Type identifier 'React$ElementProps' is not allowed. Use 'React.ElementProps' instead.typeX=React$ElementRef<typeofComponent>// Message: Type identifier 'React$ElementRef' is not allowed. Use 'React.ElementRef' instead.typeX=React$ElementType// Message: Type identifier 'React$ElementType' is not allowed. Use 'React.ElementType' instead.typeX=React$Key// Message: Type identifier 'React$Key' is not allowed. Use 'React.Key' instead.typeX=React$Node// Message: Type identifier 'React$Node' is not allowed. Use 'React.Node' instead.typeX=React$Ref<typeofComponent>// Message: Type identifier 'React$Ref' is not allowed. Use 'React.Ref' instead.typeX=React$StatelessFunctionalComponent<Props>// Message: Type identifier 'React$StatelessFunctionalComponent' is not allowed. Use 'React.StatelessFunctionalComponent' instead.

The following patterns are not considered problems:

typeX=React.AbstractComponent<Config,Instance>typeX=React.ChildrenArray<string>typeX=React.ComponentType<Props>typeX=React.Config<Props,DefaultProps>typeX=React.Element<typeofComponent>typeX=React.ElementConfig<typeofComponent>typeX=React.ElementProps<typeofComponent>typeX=React.ElementRef<typeofComponent>typeX=React.ElementTypetypeX=React.KeytypeX=React.NodetypeX=React.Ref<typeofComponent>typeX=React.StatelessFunctionalComponent<Props>typeX=React$Rocks

no-mixed

Warns against "mixed" type annotations.These types are not strict enough and could often be made more specific.

The following patterns are considered problems:

The following patterns are considered problems:

functionfoo(thing):mixed{}// Message: Unexpected use of mixed typefunctionfoo(thing):Promise<mixed>{}// Message: Unexpected use of mixed typefunction foo(thing): Promise<Promise<mixed>>{}// Message: Unexpected use of mixed type

The following patterns are not considered problems:

functionfoo(thing):string{}functionfoo(thing):Promise<string>{}function foo(thing): Promise<Promise<string>>{}(foo?: string) =>{}(foo: ?string) =>{}(foo:{a:string}) =>{}(foo:{a: ?string}) =>{}(foo: string[]) =>{}type Foo = stringtype Foo ={a:string}type Foo ={(a:string):string}function foo(thing: string){}var foo: stringclass Foo{props:string}

no-mutable-array

The--fix option on the command line automatically fixes problems reported by this rule.

Requires use of$ReadOnlyArray instead of justArray or arrayshorthand notation.$ReadOnlyArray is immutable array collection type and the superclass of Array and tuple types in Flow. Use of$ReadOnlyArray instead ofArray can solve some "problems" in typing with Flow (e.g.,1,2).

General reasons for using immutable data structures:

  • They are simpler to construct, test, and use
  • They help to avoid temporal coupling
  • Their usage is side-effect free (no defensive copies)
  • Identity mutability problem is avoided
  • They always have failure atomicity
  • They are much easier to cache

Note that initialization of a variable with an empty array is considered valid (e.g.,const values: Array<string> = [];). This behavior resembles the behavior of Flow'sunsealed objects, as it is assumed that empty array is intended to be mutated.

The following patterns are considered problems:

typeX=Array<string>// Message: Use "$ReadOnlyArray" instead of "Array"typeX=string[]// Message: Use "$ReadOnlyArray" instead of array shorthand notationconstvalues:Array<Array<string>>=[];// Message: Use "$ReadOnlyArray" instead of "Array"letvalues:Array<Array<string>>;// Message: Use "$ReadOnlyArray" instead of "Array"// Message: Use "$ReadOnlyArray" instead of "Array"

The following patterns are not considered problems:

typeX=$ReadOnlyArray<string>constvalues:Array<$ReadOnlyArray<string>>=[];constvalues:$ReadOnlyArray<string>[] = [];const values: Array<$ReadOnlyArray<string>>=newArray();constvalues:Array<$ReadOnlyArray<string>>=Array();

no-primitive-constructor-types

Disallows use of primitive constructors as types, such asBoolean,Number andString.See more.

{"rules":{"flowtype/no-primitive-constructor-types":2}}

The following patterns are considered problems:

typex=Number// Message: Unexpected use of Number constructor type.typex=String// Message: Unexpected use of String constructor type.typex=Boolean// Message: Unexpected use of Boolean constructor type.typex={a:Number}// Message: Unexpected use of Number constructor type.typex={a:String}// Message: Unexpected use of String constructor type.typex={a:Boolean}// Message: Unexpected use of Boolean constructor type.(x:Number)=>{}// Message: Unexpected use of Number constructor type.(x:String)=>{}// Message: Unexpected use of String constructor type.(x:Boolean)=>{}// Message: Unexpected use of Boolean constructor type.

The following patterns are not considered problems:

typex=numbertypex=stringtypex=booleantypex={a:number}typex={a:string}typex={a:boolean}(x:number)=>{}(x:string)=>{}(x:boolean)=>{}typex=MyNumbertypex=MyStringtypex=MyBoolean

no-types-missing-file-annotation

Disallows Flow type imports, aliases, and annotations in files missing a valid Flow file declaration (or a @noflow annotation).

{"rules":{"flowtype/no-types-missing-file-annotation":2}}

The following patterns are considered problems:

constx:number=42;// Message: Type annotations require valid Flow declaration.typeFooType=number;// Message: Type aliases require valid Flow declaration.importtypeAfrom"a"// Message: Type imports require valid Flow declaration.importtype{A}from"a"// Message: Type imports require valid Flow declaration.import{typeA}from"a"// Message: Type imports require valid Flow declaration.exporttype{A}from"a"// Message: Type exports require valid Flow declaration.functiont<T>(): T{}// Message: Type annotations require valid Flow declaration.// Settings:{"flowtype":{"onlyFilesWithFlowAnnotation":true}}const x: number = 42;// Message: Type annotations require valid Flow declaration.

The following patterns are not considered problems:

//@flowconstx:number=42;/*@flow weak */typeFooType=number;/*@noflow */typeFooType=number;/*@noflow */importtypeAfrom"a"/*@noflow */import{typeA}from"a"/*@noflow */exporttype{A}from"a"// an unrelated comment//@flowexporttype{A}from"a"

no-unused-expressions

An extension ofESLint'sno-unused-expressions.This rule ignores type cast expressions and optional call expressions, but otherwise behaves the same as ESLint'sno-unused-expressions.

Bare type casts are useful, for example to assert the exhaustiveness of aswitch:

typeAction={type:'FOO',doFoo:(_:number)=>void}|{type:'BAR',doBar:(_:string)=>void};typeState={foo:number,bar:string};functionrunFooBar(action:Action,state:State):void{switch(action.type){case'FOO':doFoo(state.foo);break;case'BAR':doBar(state.bar);break;default:(action:empty);// type error when `Action` is extended with new typesconsole.error(`Impossible action:${action.toString()}`);}}

This rule takes the same arguments as ESLint'sno-unused-expressions. Seethat rule's documentation for details.

The following patterns are considered problems:

foo+1// Message: Expected an assignment or function call and instead saw an expression.x?.y// Message: Expected an assignment or function call and instead saw an expression.

The following patterns are not considered problems:

(foo:number)x?.y()

no-weak-types

Warns against weak type annotationsany,Object andFunction.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 thewarnings are enabled. e.g. to disable theany warning (allowing it to exist in your code), while continuing to warnaboutObject andFunction:

{"rules":{"flowtype/no-weak-types":[2,{"any":false,"Object":true,"Function":true}]}}// or, the following is equivalent as default is true:{"rules":{"flowtype/no-weak-types":[2,{"any":false}]}}

The following patterns are considered problems:

functionfoo(thing):any{}// Message: Unexpected use of weak type "any"functionfoo(thing):Promise<any>{}// Message: Unexpected use of weak type "any"function foo(thing): Promise<Promise<any>>{}// Message: Unexpected use of weak type "any"function foo(thing): Object{}// Message: Unexpected use of weak type "Object"function foo(thing): Promise<Object>{}// Message: Unexpected use of weak type "Object"function foo(thing): Promise<Promise<Object>>{}// Message: Unexpected use of weak type "Object"function foo(thing): Function{}// Message: Unexpected use of weak type "Function"function foo(thing): Promise<Function>{}// Message: Unexpected use of weak type "Function"function foo(thing): Promise<Promise<Function>>{}// Message: Unexpected use of weak type "Function"(foo: any) =>{}// Message: Unexpected use of weak type "any"(foo: Function) =>{}// Message: Unexpected use of weak type "Function"(foo?: any) =>{}// Message: Unexpected use of weak type "any"(foo?: Function) =>{}// Message: Unexpected use of weak type "Function"(foo:{a:any}) =>{}// Message: Unexpected use of weak type "any"(foo:{a:Object}) =>{}// Message: Unexpected use of weak type "Object"(foo: any[]) =>{}// Message: Unexpected use of weak type "any"type Foo = any// Message: Unexpected use of weak type "any"type Foo = Function// Message: Unexpected use of weak type "Function"type Foo ={a:any}// Message: Unexpected use of weak type "any"type Foo ={a:Object}// Message: Unexpected use of weak type "Object"type Foo ={(a:Object):string}// Message: Unexpected use of weak type "Object"type Foo ={(a:string):Function}// Message: Unexpected use of weak type "Function"function foo(thing: any){}// Message: Unexpected use of weak type "any"function foo(thing: Object){}// Message: Unexpected use of weak type "Object"var foo: Function// Message: Unexpected use of weak type "Function"var foo: Object// Message: Unexpected use of weak type "Object"class Foo{props:any}// Message: Unexpected use of weak type "any"class Foo{props:Object}// Message: Unexpected use of weak type "Object"var foo: any// Message: Unexpected use of weak type "any"// Options: [{"Function":false}]type X = any; type Y = Function; type Z = Object// Message: Unexpected use of weak type "any"// Message: Unexpected use of weak type "Object"// Options: [{"any":false,"Object":false}]type X = any; type Y = Function; type Z = Object// Message: Unexpected use of weak type "Function"

The following patterns are not considered problems:

functionfoo(thing):string{}functionfoo(thing):Promise<string>{}function foo(thing): Promise<Promise<string>>{}(foo?: string) =>{}(foo: ?string) =>{}(foo:{a:string}) =>{}(foo:{a: ?string}) =>{}(foo: string[]) =>{}type Foo = stringtype Foo ={a:string}type Foo ={(a:string):string}function foo(thing: string){}var foo: stringclass Foo{props:string}// Options: [{"any":false,"Object":false}]type X = any; type Y = Object// Options: [{"Function":false}]type X = Function// Settings:{"flowtype":{"onlyFilesWithFlowAnnotation":true}}function foo(thing): Function{}

object-type-curly-spacing

The--fix option on the command line automatically fixes problems reported by this rule.

This rule enforces consistent spacing inside braces of object types.

Options

The rule has a string option:

  • "never" (default): disallows spacing inside of braces.
  • "always": requires spacing inside of braces.

The following patterns are considered problems:

typeobj={"foo":"bar"}// Message: There must be no space after "{".// Message: There must be no space before "}".typeobj={"foo":"bar"}// Message: There must be no space before "}".typeobj={"foo":"bar", ...}// Message: There must be no space before "}".typeobj={|"foo":"bar"|}// Message: There must be no space before "|}".typeobj={"foo":"bar",[key:string]:string}// Message: There must be no space before "}".typeobj={"foo":"bar",[key:string]:string}// Message: There must be no space before "}".typeobj={baz:{"foo":"qux"},bar:4}// Message: There must be no space after "{".// Options: ["always"]typeobj={"foo":"bar"}// Message: A space is required after "{".// Message: A space is required before "}".// Options: ["always"]typeobj={"foo":"bar"}// Message: A space is required after "{".// Options: ["always"]typeobj={baz:{"foo":"qux"},bar:4}// Message: A space is required before "}".// Message: A space is required after "{".// Message: A space is required before "}".// Options: ["always"]typeobj={baz:{"foo":"qux"},bar:4}// Message: A space is required before "}".// Options: ["always"]typeobj={"foo":"bar", ...}// Message: A space is required before "}".// Options: ["always"]typeobj={|"foo":"bar"|}// Message: A space is required after "{|".// Options: ["always"]typeobj={"foo":"bar",[key:string]:string}// Message: A space is required after "{".

The following patterns are not considered problems:

typeobj={baz:{"foo":"qux"},bar:4}typeobj={foo:{"foo":"qux"}}typeobj={foo:"bar"}typeobj={foo:"bar"}typeobj={foo:"bar"}typeobj={foo:"bar"}typeobj={foo:"bar",ee:"bar",}typeobj={foo:"bar",ee:"bar",}typeobj={|"foo":"bar"|}typeobj={"foo":"bar",[key:string]:string}// Options: ["always"]typeobj={baz:{"foo":"qux"},bar:4}// Options: ["always"]typeobj={}// Options: ["always"]typeobj={foo:"bar"}// Options: ["always"]typeobj={baz:4}// Options: ["always"]typeobj={|"foo":"bar"|}// Options: ["always"]typeobj={"foo":"bar",[key:string]:string}// Options: ["always"]typeobj={baz:{"foo":"qux"},bar:4}// Options: ["always"]typeobj={baz:{"foo":"qux"},bar:4}

object-type-delimiter

The--fix option on the command line automatically fixes problems reported by this rule.

Enforces consistent separators between properties in Flow object types.

This rule takes one argument.

If it is'comma' then a problem is raised when using; as a separator.

If it is'semicolon' then a problem is raised when using, as a separator.

The default value is'comma'.

This rule is ported frombabel/flow-object-type, however the default option was changed.

The following patterns are considered problems:

// Options: ["semicolon"]typeFoo={a:Foo,b:Bar}// Message: Prefer semicolons to commas in object and class types// Options: ["comma"]typeFoo={a:Foo; b:Bar}// Message: Prefer commas to semicolons in object and class types// Options: ["semicolon"]typeFoo={[a:string]:Foo,[b:string]:Bar}// Message: Prefer semicolons to commas in object and class types// Options: ["comma"]typeFoo={[a:string]:Foo;[b:string]:Bar}// Message: Prefer commas to semicolons in object and class types// Options: ["semicolon"]typeFoo={():Foo,():Bar}// Message: Prefer semicolons to commas in object and class types// Options: ["comma"]typeFoo={():Foo;():Bar}// Message: Prefer commas to semicolons in object and class types// Options: ["semicolon"]declareclassFoo{a:Foo,}// Message: Prefer semicolons to commas in object and class types// Options: ["comma"]declareclassFoo{a:Foo;}// Message: Prefer commas to semicolons in object and class types// Options: ["semicolon"]declareclassFoo{[a:string]:Foo,}// Message: Prefer semicolons to commas in object and class types// Options: ["comma"]declareclassFoo{a:Foo;}// Message: Prefer commas to semicolons in object and class types// Options: ["semicolon"]declareclassFoo{():Foo,}// Message: Prefer semicolons to commas in object and class types// Options: ["comma"]declareclassFoo{():Foo;}// Message: Prefer commas to semicolons in object and class types// Options: ["semicolon"]declareclassFoo{static():Foo,}// Message: Prefer semicolons to commas in object and class types// Options: ["comma"]declareclassFoo{static():Foo;}// Message: Prefer commas to semicolons in object and class types

The following patterns are not considered problems:

// Options: ["semicolon"]typeFoo={a:Foo; b:Bar}// Options: ["comma"]typeFoo={a:Foo,b:Bar}// Options: ["semicolon"]typeFoo={[a:string]:Foo;[b:string]:Bar}// Options: ["comma"]typeFoo={[a:string]:Foo,[b:string]:Bar}// Options: ["semicolon"]typeFoo={():Foo;():Bar}// Options: ["comma"]typeFoo={():Foo,():Bar}typeFoo={a:Foo,b:Bar}typeFoo={[a:string]:Foo,[b:string]:Bar}typeFoo={():Foo,():Bar}// Options: ["semicolon"]declareclassFoo{a:Foo;}// Options: ["comma"]declareclassFoo{a:Foo,}// Options: ["semicolon"]declareclassFoo{[a:string]:Foo;}// Options: ["comma"]declareclassFoo{[a:string]:Foo,}// Options: ["semicolon"]declareclassFoo{():Foo;}// Options: ["comma"]declareclassFoo{():Foo,}// Options: ["semicolon"]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeFoo={a:Foo,b:Bar}

quotes

Enforces single quotes or double quotes around string literals.

Options

The rule has string options of:

  • "double" (default) requires double quotes around string literals.
  • "single" requires single quotes around string literals.

The following patterns are considered problems:

typeT='hi'// Message: String literals must use double quote.// Options: ["double"]typeT={test:'hello'|'test'}// Message: String literals must use double quote.// Message: String literals must use double quote.// Options: ["double"]typeT={test:"hello"|'test',t:'hello'}// Message: String literals must use double quote.// Message: String literals must use double quote.// Options: ["single"]typeT="hi"// Message: String literals must use single quote.// Options: ["single"]typeT={test:"hello"|"test"}// Message: String literals must use single quote.// Message: String literals must use single quote.// Options: ["single"]typeT={test:"hello"|'test',t:'hello'}// Message: String literals must use single quote.

The following patterns are not considered problems:

// Options: ["double"]typeT="hi"// Options: ["double"]typeT={test:"hello"|"test"}// Options: ["double"]typeT={test:"hello"|"test",t:"hello"}// Options: ["single"]typeFooType='hi'// Options: ["single"]typeT={test:'hello'|'test'}// Options: ["single"]typeT={test:'hello'|'test',t:'hello'}

require-compound-type-alias

Requires to make a type alias for allunion andintersection types. If these are used in "raw" forms it might be tempting to just copy & paste them around the code. However, this brings sort of a source code pollution and unnecessary changes on several parts when these compound types need to be changed.

Options

The rule has two options:

  1. a string option
  • "always" (default)
  • "never"
  1. an object
{"rules":{"flowtype/require-compound-type-alias":[2,"always",{"allowNull":true}]}}
  • allowNull – allows compound types where one of the members is anull, e.g.string | null.

The following patterns are considered problems:

// Options: ["always",{"allowNull":false}]constfoo:string|null=null;// Message: All union types must be declared with named type alias.functionfoo(bar:"A"|"B"){}// Message: All union types must be declared with named type alias.constfoo:"A"|"B"="A";// Message: All union types must be declared with named type alias.typeFoo={bar:"A"|"B"};// Message: All union types must be declared with named type alias.functionfoo(bar:{n:number}|{s:string}){}// Message: All union types must be declared with named type alias.functionfoo(bar:{n:number}&{s:string}){}// Message: All intersection types must be declared with named type alias.constfoo:{n:number}&{s:string}={n:0,s:""};// Message: All intersection types must be declared with named type alias.typeFoo={bar:{n:number}&{s:string}};// Message: All intersection types must be declared with named type alias.functionfoo(bar:{n:number}&{s:string}){}// Message: All intersection types must be declared with named type alias.

The following patterns are not considered problems:

constfoo:string|null=null;// Options: ["always",{"allowNull":true}]constfoo:string|null=null;typeFoo="A"|"B";typeBar="A"|"B";functionfoo(bar:Bar){}typeFoo={disjoint:"A",n:number}|{disjoint:"B",s:string};typeFoo={n:number}&{s:string};typeBar={n:number}&{s:string};functionfoo(bar:Bar){}// Options: ["never"]functionfoo(bar:"A"|"B"){}// Options: ["never"]functionfoo(bar:{n:number}&{s:string}){}

require-exact-type

The--fix option on the command line automatically fixes problems reported by this rule.

This rule enforcesexact object types.

Options

The rule has one string option:

  • "always" (default): Report all object type definitions that aren't exact.
  • "never": Report all object type definitions that are exact.
{"rules":{"flowtype/require-exact-type":[2,"always"]}}{"rules":{"flowtype/require-exact-type":[2,"never"]}}

The following patterns are considered problems:

typefoo={};// Message: Object type must be exact.typefoo={bar:string};// Message: Object type must be exact.// Options: ["always"]typefoo=Array<{bar:string}>;// Message: Object type must be exact.// Options: ["always"](foo:Array<{bar:string}>)=>{};// Message: Object type must be exact.// Options: ["always"]interfaceStackFrame{colno?:number;lineno?:number;filename?:string;function?:{name:string};}// Message: Object type must be exact.// Options: ["never"]typefoo={||};// Message: Object type must not be exact.// Options: ["never"]typefoo={|bar:string|};// Message: Object type must not be exact.// Options: ["never"]typefoo={bar:{|baz:string|}};// Message: Object type must not be exact.// Options: ["never"]typefoo=Array<{|bar:string|}>;// Message: Object type must not be exact.// Options: ["never"](foo:Array<{|bar:string|}>)=>{};// Message: Object type must not be exact.// Options: ["never"]interfaceStackFrame{colno?:number;lineno?:number;filename?:string;function?:{|name:string|};}// Message: Object type must not be exact.

The following patterns are not considered problems:

typefoo={||};typefoo={|bar:string|};typefoo={[key:string]:string};typefoo=number;// Options: ["always"]typefoo={||};// Options: ["always"]typefoo={|bar:string|};// Options: ["always"]typefoo={|bar:{|baz:string|}|};// Options: ["always"]typefoo=Array<{|bar:string|}>;// Options: ["always"]typefoo=number;// Options: ["always"]interfaceStackFrame{colno?:number;lineno?:number;filename?:string;function?:{|name:string|};}// Options: ["always"]declareclassMyEventextendsEvent{key:string}// Options: ["never"]typefoo={};// Options: ["never"]typefoo={bar:string};// Options: ["never"]typefoo={bar:{baz:string}};// Options: ["never"]typefoo=Array<{bar:string}>;// Options: ["never"]typefoo=number;// Options: ["always"]interfaceStackFrame{colno?:number;lineno?:number;filename?:string;function?:{|name:string|};}typeA={a:string, ...}

require-indexer-name

The--fix option on the command line automatically fixes problems reported by this rule.

This rule validates Flow object indexer name.

Options

The rule has a string option:

  • "never" (default): Never report files that are missing an indexer key name.
  • "always": Always report files that are missing an indexer key name.
{"rules":{"flowtype/require-indexer-name":[2,"always"]}}

The following patterns are considered problems:

typefoo={[string]:number};// Message: All indexers must be declared with key name.

The following patterns are not considered problems:

typefoo={[key:string]:number};// Options: ["never"]typefoo={[key:string]:number};// Options: ["never"]typefoo={[string]:number};

require-inexact-type

This rule enforces explicit inexact object types.

Options

The rule has one string option:

  • "always" (default): Report all object type definitions that aren't explicit inexact, but ignore exact objects.
  • "never": Report all object type definitions that are explicit inexact.
{"rules":{"flowtype/require-inexact-type":[2,"always"]}}{"rules":{"flowtype/require-inexact-type":[2,"never"]}}

The following patterns are considered problems:

typefoo={};// Message: Type must be explicit inexact.typefoo={bar:string};// Message: Type must be explicit inexact.// Options: ["always"]typefoo={};// Message: Type must be explicit inexact.// Options: ["always"]typefoo={bar:string};// Message: Type must be explicit inexact.// Options: ["never"]typefoo={...};// Message: Type must not be explicit inexact.// Options: ["never"]typefoo={bar:string, ...};// Message: Type must not be explicit inexact.

The following patterns are not considered problems:

typefoo={foo:string, ...};interfaceFoo{foo:string}declareclassFoo{foo:string}typefoo={||};typefoo={|bar:string|};typefoo={[key:string]:string, ...};typefoo=number;// Options: ["always"]typefoo={||};// Options: ["always"]typefoo={...};// Options: ["always"]typefoo={bar:string, ...};// Options: ["always"]typefoo={|bar:string|};// Options: ["always"]typefoo=number;// Options: ["never"]typefoo={};// Options: ["never"]typefoo={||};// Options: ["never"]typefoo={bar:string};// Options: ["never"]typefoo={|bar:string|};// Options: ["never"]typefoo=number;

require-parameter-type

Requires that all function parameters have type annotations.

Options

You can skip all arrow functions by providing theexcludeArrowFunctions option withtrue.

Alternatively, you can want to exclude only concise arrow functions (e.g.x => x * 2). ProvideexcludeArrowFunctions withexpressionsOnly for this.

{"rules":{"flowtype/require-parameter-type":[2,{"excludeArrowFunctions":true}]}}{"rules":{"flowtype/require-parameter-type":[2,{"excludeArrowFunctions":"expressionsOnly"}]}}

You can exclude parameters that match a certain regex by usingexcludeParameterMatch.

{"rules":{"flowtype/require-parameter-type":[2,{"excludeParameterMatch":"^_"}]}}

This excludes all parameters that start with an underscore (_).The default pattern isa^, which doesn't match anything, i.e., all parameters are checked.

The following patterns are considered problems:

(foo)=>{}// Message: Missing "foo" parameter type annotation.functionx(foo){}// Message: Missing "foo" parameter type annotation.// Options: [{"excludeArrowFunctions":true}]functionx(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.// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}//@flow(foo)=>{}// Message: Missing "foo" parameter type annotation.// Options: [{"excludeArrowFunctions":"expressionsOnly"}](foo)=>{}// Message: Missing "foo" parameter type annotation.// Options: [{"excludeArrowFunctions":"expressionsOnly"}]functionx(foo){}// Message: Missing "foo" parameter type annotation.// Options: [{"excludeParameterMatch":"^_"}](_foo:number,bar)=>{}// Message: Missing "bar" parameter type annotation.// Options: [{"excludeParameterMatch":"^_"}](_foo,bar)=>{}// Message: Missing "bar" parameter type annotation.

The following patterns are not considered problems:

(foo:string)=>{}(foo:string='FOO')=>{}(...foo:string)=>{}constf:Foo=(a,b)=>42;({foo}:{foo:string})=>{}([foo]:Array)=>{}typefn=(a:string,b:number)=>number;constf:fn=(a,b)=>{}// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}(foo)=>{}// Options: [{"excludeArrowFunctions":true}](foo)=>{}// Options: [{"excludeArrowFunctions":"expressionsOnly"}](foo)=>3// Options: [{"excludeParameterMatch":"^_"}](_foo,bar:string)=>{}// Options: [{"excludeParameterMatch":"^_"}](_foo:number,bar:string)=>{}// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}(foo)=>{}

require-readonly-react-props

This rule validates that React props are marked as$ReadOnly. React props are immutable and modifying them could lead to unexpected results. Marking prop shapes as$ReadOnly avoids these issues.

The rule tries its best to work with both class and functional components. For class components, it does a fuzzy check for one of "Component", "PureComponent", "React.Component" and "React.PureComponent". It doesn't actually infer that those identifiers resolve to a properReact.Component object.

For example, this will NOT be checked:

importMyReactfrom'react';classFooextendsMyReact.Component{}

As a result, you can safely use other classes without getting warnings from this rule:

classMyClassextendsMySuperClass{}

React's functional components are hard to detect statically. The way it's done here is by searching for JSX within a function. When present, a function is considered a React component:

// this gets checkedtypeProps={};functionMyComponent(props:Props){return<p/>;}// this doesn't get checked since no JSX is present in a functiontypeOptions={};functionSomeHelper(options:Options){// ...}// this doesn't get checked since no JSX is present directly in a functionfunctionhelper(){return<p/>}functionMyComponent(props:Props){returnhelper();}

The rule only works for locally defined props that are marked with a$ReadOnly or using covariant notation. It doesn't work with imported props:

// the rule has no way of knowing whether ImportedProps are read-onlyimport{typeImportedProps}from'./somewhere';classFooextendsReact.Component<ImportedProps>{}// the rule also checks for covariant propertiestypeProps={|+foo:string|};classBarextendsReact.Component<Props>{}// this fails because the object is not fully read-onlytypeProps={|+foo:string,bar:number,|};classBarextendsReact.Component<Props>{}// this fails because spreading makes object mutable (as of Flow 0.98)// https://github.com/gajus/eslint-plugin-flowtype/pull/400#issuecomment-489813899typeProps={|+foo:string,    ...bar,|};classBarextendsReact.Component<Props>{}
{"rules":{"flowtype/require-readonly-react-props":2}}

Optionally, you can enable support forimplicit exact Flow types (useful when usingexact_by_default=true Flow option):

{"rules":{"flowtype/require-readonly-react-props":[2,{"useImplicitExactTypes":true}]}}

The following patterns are considered problems:

typeProps={};classFooextendsReact.Component<Props>{}// Message: Props must be $ReadOnlytypeOtherProps={foo:string};classFooextendsReact.Component<OtherProps>{}// Message: OtherProps must be $ReadOnlyclassFooextendsReact.Component<{}>{}// Message: Foo class props must be $ReadOnlytypeProps={bar:{}};classFooextendsReact.Component<Props,State>{}// Message: Props must be $ReadOnlytypeProps={};classFooextendsComponent<Props>{}// Message: Props must be $ReadOnlytypeProps={};classFooextendsPureComponent<Props>{}// Message: Props must be $ReadOnlyexporttypeProps={};classFooextendsComponent<Props>{}// Message: Props must be $ReadOnlytypeProps={|foo:string|};classFooextendsComponent<Props>{}// Message: Props must be $ReadOnlytypeProps={|foo:string|}|{|bar:number|};classFooextendsComponent<Props>{}// Message: Props must be $ReadOnly// Options: [{"useImplicitExactTypes":true}]typeProps={foo:string}|{bar:number};classFooextendsComponent<Props>{}// Message: Props must be $ReadOnlytypeProps={|+foo:string, ...bar|};classFooextendsComponent<Props>{}// Message: Props must be $ReadOnlytypeProps={|+foo:string,-bar:number|};classFooextendsComponent<Props>{}// Message: Props must be $ReadOnlytypeProps={};functionFoo(props:Props){return<p/>}// Message: Props must be $ReadOnlytypeProps={};functionFoo(props:Props){returnfoo ?<p/> :<span/>}// Message: Props must be $ReadOnlyfunctionFoo(props:{}){return<p/>}// Message: Foo component props must be $ReadOnlyexporttypeProps={};functionFoo(props:Props){return<p/>}// Message: Props must be $ReadOnly

The following patterns are not considered problems:

classFooextendsReact.Component<$ReadOnly<{}>>{}typeProps=$ReadOnly<{}>;classFooextendsReact.Component<Props>{}typeProps=$ReadOnly<{}>;classFooextendsReact.PureComponent<Props>{}classFooextendsReact.Component<$ReadOnly<{},State>>{}typeProps=$ReadOnly<{}>;classFooextendsReact.Component<Props,State>{}typeProps=$ReadOnly<{}>;classFooextendsComponent<Props>{}typeProps=$ReadOnly<{}>;classFooextendsPureComponent<Props>{}typeFooType={};classFooextendsBar<FooType>{}classFoo{}exporttypeProps=$ReadOnly<{}>;classFooextendsComponent<Props,State>{}exporttypeProps=$ReadOnly<{}>;exportclassFooextendsComponent<Props>{}typeProps={|+foo:string|};classFooextendsComponent<Props>{}typeProps={|+foo:string,+bar:number|};classFooextendsComponent<Props>{}typeProps={|+foo:string|}|{|+bar:number|};classFooextendsComponent<Props>{}// Options: [{"useImplicitExactTypes":true}]typeProps={+foo:string}|{+bar:number};classFooextendsComponent<Props>{}typeProps=$FlowFixMe;classFooextendsComponent<Props>{}typeProps={||};classFooextendsComponent<Props>{}// Options: [{"useImplicitExactTypes":true}]typeProps={||};classFooextendsComponent<Props>{}// Options: [{"useImplicitExactTypes":true}]typeProps={};classFooextendsComponent<Props>{}classFooextendsComponent<{||}>{}// Options: [{"useImplicitExactTypes":true}]classFooextendsComponent<{||}>{}// Options: [{"useImplicitExactTypes":true}]classFooextendsComponent<{}>{}classFooextendsReact.Component<UnknownProps>{}import{typeProps}from"file";classFooextendsReact.Component<Props>{}typeProps={};functionFoo(){}typeProps=$ReadOnly<{}>;functionFoo(props:Props){}typeProps={};functionFoo(props:OtherProps){}functionFoo(){return<p/>}functionFoo(props:$FlowFixMe){return<p/>}functionFoo(props:{||}){return<p/>}// Options: [{"useImplicitExactTypes":true}]functionFoo(props:{||}){return<p/>}// Options: [{"useImplicitExactTypes":true}]functionFoo(props:{}){return<p/>}

require-return-type

Requires that functions have return type annotation.

Options

You can skip all arrow functions by providing theexcludeArrowFunctions option withtrue.

Alternatively, you can exclude a concise arrow function (e.g.() => 2). ProvideexcludeArrowFunctions withexpressionsOnly for this.

{"rules":{"flowtype/require-return-type":[2,"always",{"excludeArrowFunctions":true}]}}{"rules":{"flowtype/require-return-type":[2,"always",{"excludeArrowFunctions":"expressionsOnly"}]}}

You can exclude or include specific tests with theincludeOnlyMatching andexcludeMatching rules.

{"rules":{"flowtype/require-return-type":[2,"always",{"includeOnlyMatching":["^F.*","Ba(r|z)"]}]}}{"rules":{"flowtype/require-return-type":[2,"always",{"excludeMatching":["^F.*","Ba(r|z)"]}]}}

Both rules take an array that can contain either strings or valid RegExp statements.

The following patterns are considered problems:

(foo)=>{return"foo";}// Message: Missing return type annotation.// Options: ["always"](foo)=>{return"foo";}// Message: Missing return type annotation.// Options: ["always"](foo)=>"foo"// Message: Missing return type annotation.(foo)=>({})// Message: Missing return type annotation./*@flow */(foo)=>{return1;}// Message: Missing return type annotation.(foo):undefined=>{ return;}// Message: Must not annotate undefined return type.(foo):void=>{return;}// Message: Must not annotate undefined return type.(foo):undefined=>{returnundefined;}// Message: Must not annotate undefined return type.(foo):void=>{returnvoid0;}// Message: Must not annotate undefined return type.// Options: ["always",{"annotateUndefined":"never"}](foo):undefined=>{ return;}// Message: Must not annotate undefined return type.// Options: ["always",{"annotateUndefined":"never"}](foo):void=>{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=>{returnundefined;}// Message: Must not annotate undefined return type.// Options: ["always",{"annotateUndefined":"always"}](foo)=>{returnundefined;}// Message: Must annotate undefined return type.// Options: ["always",{"annotateUndefined":"always"}](foo)=>{returnvoid0;}// Message: Must annotate undefined return type.// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}//@flow(foo)=>{return1;}// Message: Missing return type annotation.// Options: ["always",{"annotateUndefined":"always"}]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}//@flow(foo)=>{returnundefined;}// Message: Must annotate undefined return type.// Options: ["always"]async()=>{return2;}// Message: Missing return type annotation.// Options: ["always",{"annotateUndefined":"always"}]async()=>{}// Message: Must annotate undefined return type.// Options: ["always",{"annotateUndefined":"always"}]asyncfunctionx(){}// Message: Must annotate undefined return type.// Options: ["always",{"annotateUndefined":"never"}]async():Promise<void>=>{return;}// Message: Must not annotate undefined return type.// Options: ["always",{"annotateUndefined":"never"}]async():Promise<undefined>=>{return;}// Message: Must not annotate undefined return type.// Options: ["always",{"annotateUndefined":"always"}]classTest{constructor(){}}// Message: Must annotate undefined return type.classTest{foo(){return42;}}// Message: Missing return type annotation.classTest{foo=()=>{return42;}}// Message: Missing return type annotation.classTest{foo=()=>42;}// Message: Missing return type annotation.// Options: ["always"]function*x(){}// Message: Missing return type annotation.// Options: ["always",{"excludeArrowFunctions":"expressionsOnly"}]()=>{return3;}// Message: Missing return type annotation.// Options: ["always",{"excludeArrowFunctions":"expressionsOnly"}]async()=>{return4;}// Message: Missing return type annotation.// Options: ["always",{"includeOnlyMatching":["bar"]}]functionfoo(){return42;}functionbar(){return42;}// Message: Missing return type annotation.// Options: ["always",{"includeOnlyMatching":["bar"]}]constfoo=()=>{return42;};constbar=()=>{return42;}// Message: Missing return type annotation.// Options: ["always",{"includeOnlyMatching":["bar"]}]constfoo={bar(){return42;},foobar:function(){return42;}}// Message: Missing return type annotation.// Message: Missing return type annotation.// Options: ["always",{"excludeMatching":["bar"]}]constfoo={bar(){return42;},baz(){return42;}}// Message: Missing return type annotation.// Options: ["always",{"annotateUndefined":"always"}]function*foo(){yield2;}// Message: Missing return type annotation.// Options: ["always",{"annotateUndefined":"always"}]asyncfunction*foo(){yield2;}// Message: Missing return type annotation.

The following patterns are not considered problems:

return;(foo):string=>{}constf:Foo=(a,b)=>42;// Options: ["always"](foo):string=>{}typefn=(a:string,b:number)=>number;constf:fn=(a,b)=>{return42;}(foo)=>{ return;}(foo):Object=>({})(foo)=>{returnundefined;}(foo)=>{returnvoid0;}// Options: ["always",{"annotateUndefined":"always"}](foo):undefined=>{ return;}// Options: ["always",{"annotateUndefined":"always"}](foo):void=>{return;}// Options: ["always",{"annotateUndefined":"never"}](foo)=>{return;}// Options: ["always",{"annotateUndefined":"never"}](foo)=>{returnundefined;}// Options: ["always",{"annotateUndefined":"never"}](foo)=>{returnvoid0;}// Options: ["always",{"annotateUndefined":"always"}](foo):undefined=>{returnundefined;}// Options: ["always",{"annotateUndefined":"always"}](foo):void=>{returnvoid0;}// Options: ["always"]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}(foo)=>{return1;}// Options: ["always"]/*@noflow */(foo)=>{return1;}// Options: ["always",{"annotateUndefined":"always"}]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}(foo)=>{returnundefined;}// Options: ["always",{"annotateUndefined":"always"}]asyncfunctiondoThing():Promise<void>{}// Options: ["always",{"annotateUndefined":"ignore"}]asyncfunctiondoThing():Promise<void>{}// Options: ["always",{"annotateUndefined":"ignore"}]asyncfunctiondoThing(){}// Options: ["always",{"annotateUndefined":"always"}]function*doThing():Generator<number,void,void>{yield2;}// Options: ["always",{"annotateUndefined":"always","excludeMatching":["constructor"]}]classTest{constructor(){}}classTest{constructor(){}}// Options: ["always",{"excludeMatching":["foo"]}]classTest{foo(){return42;}}// Options: ["always",{"excludeMatching":["foo"]}]classTest{foo=()=>{return42;}}// Options: ["always",{"excludeMatching":["foo"]}]classTest{foo=()=>42;}classTest{foo=():number=>{return42;}}classTest{foo=():number=>42;}async(foo):Promise<number>=>{ return3;}// Options: ["always",{"excludeArrowFunctions":true}]()=>3// Options: ["always",{"excludeArrowFunctions":true}]()=>{return4;}// Options: ["always",{"excludeArrowFunctions":true}]()=>undefined// Options: ["always",{"annotateUndefined":"always","excludeArrowFunctions":true}]()=>undefined// Options: ["always",{"annotateUndefined":"always","excludeArrowFunctions":true}]()=>{returnundefined;}// Options: ["always",{"excludeArrowFunctions":"expressionsOnly"}]()=>3// Options: ["always",{"excludeArrowFunctions":"expressionsOnly"}]async()=>3// Options: ["always",{"excludeMatching":["foo"]}]functionfoo(){return42;}// Options: ["always",{"includeOnlyMatching":["bar"]}]functionfoo(){return42;}// Options: ["always",{"excludeMatching":["bar"]}]functionfoo():number{return42;}functionbar(){return42;}// Options: ["always",{"includeOnlyMatching":["foo","baz"]}]functionfoo():number{return42;}functionbar(){return42;}// Options: ["always",{"excludeMatching":["^b.*","qux"]}]functionfoo():number{return42;}functionbar(){return42;}// Options: ["always",{"includeOnlyMatching":["^f.*"]}]functionfoo():number{return42;}functionbar(){return42;}// Options: ["always",{"includeOnlyMatching":["bar"]}]constfoo={baz(){return42;}}// Options: ["always",{"excludeMatching":["bar"]}]constfoo={bar(){return42;}}// Options: ["always",{"annotateUndefined":"always"}]function*foo():Iterable<number>{yield2;}// Options: ["always",{"annotateUndefined":"always"}]asyncfunction*foo():AsyncIterable<number>{ yield2;}

require-types-at-top

Requires all type declarations to be at the top of the file, after any import declarations.

Options

The rule has a string option:

  • "never"
  • "always"

The default value is"always".

The following patterns are considered problems:

constfoo=3;typeFoo=number;// Message: All type declaration must be at the top of the file, after any import declarations.constfoo=3;opaquetypeFoo=number;// Message: All type declaration must be at the top of the file, after any import declarations.constfoo=3;exporttypeFoo=number;// Message: All type declaration must be at the top of the file, after any import declarations.constfoo=3;exportopaquetypeFoo=number;// Message: All type declaration must be at the top of the file, after any import declarations.constfoo=3;typeFoo=number|string;// Message: All type declaration must be at the top of the file, after any import declarations.importbarfrom"./bar";constfoo=3;typeFoo=number;// Message: All type declaration must be at the top of the file, after any import declarations.

The following patterns are not considered problems:

typeFoo=number;constfoo=3;opaquetypeFoo=number;constfoo=3;exporttypeFoo=number;constfoo=3;exportopaquetypeFoo=number;constfoo=3;typeFoo=number;constfoo=3;importbarfrom"./bar";typeFoo=number;typeFoo=number;importbarfrom"./bar";// Options: ["never"]constfoo=3;typeFoo=number;

require-valid-file-annotation

This rule validates Flow file annotations.

This rule can optionally report missing or missed placed annotations, common typos (e.g.// @floww), and enforce a consistent annotation style.

Options

The rule has a string option:

  • "never" (default): Never report files that are missing an@flow annotation.
  • "always": Always report files that are missing an@flow annotation

This rule has an object option:

  • "annotationStyle" - Enforce a consistent file annotation style.

    • "none" (default): Either annotation style is accepted.
    • "line": Require single line annotations (i.e.// @flow).
    • "block": Require block annotations (i.e./* @flow */).
  • "strict" - Enforce a strict flow file annotation.

    • false (default): strict flow annotation is not required.
    • true: Require strict flow annotation (i.e.// @flow strict).
{"rules":{"flowtype/require-valid-file-annotation":[2,"always"]}}{"rules":{"flowtype/require-valid-file-annotation":[2,"always",{"annotationStyle":"block","strict":true,}]}}

The following patterns are considered problems:

// Options: ["always"]#!/usr/bin/env node// Message: Flow file annotation is missing.// Options: ["always"]#!/usr/bin/env nodea;// Message: Flow file annotation is missing.;//@flow// Message: Flow file annotation not at the top of the file.;//@flow// Message: Flow file annotation not at the top of the file.//@Flow// Message: Malformed Flow file annotation.//@NoFlow// Message: Malformed Flow file annotation.//@Noflow// Message: Malformed Flow file annotation.//@floweeeeeee// Message: Misspelled or malformed Flow file annotation.//@nofloweeeeeee// Message: Misspelled or malformed Flow file annotation.// Options: ["always"]a;// Message: Flow file annotation is missing.// Options: ["always",{"annotationStyle":"line"}]/*@flow */// Message: Flow file annotation style must be `// @flow`// Options: ["always",{"annotationStyle":"block"}]//@flow// Message: Flow file annotation style must be `/*@flow */`// Options: ["always",{"annotationStyle":"block"}]//@flow// Message: Flow file annotation style must be `/*@flow */`// Options: ["always",{"annotationStyle":"line","strict":true}]//@flow// Message: Strict Flow file annotation is required, must be `// @flow strict`// Options: ["always",{"annotationStyle":"line"}]/*@noflow */// Message: Flow file annotation style must be `// @noflow`// Options: ["always",{"annotationStyle":"block"}]//@noflow// Message: Flow file annotation style must be `/*@noflow */`// Options: ["always"]a;// Message: Flow file annotation is missing.// Options: ["always",{"annotationStyle":"block"}]a;// Message: Flow file annotation is missing.// Options: ["always",{"annotationStyle":"line","strict":true}]a;// Message: Flow file annotation is missing.// Options: ["always",{"annotationStyle":"line","strict":true}]//@flowa;b;// Message: Strict Flow file annotation is required, must be `// @flow strict`// Options: ["never",{"annotationStyle":"line"}]/*@flow */a;b;// Message: Flow file annotation style must be `// @flow`// Options: ["never",{"annotationStyle":"line"}]/*@flow strict */a;b;// Message: Flow file annotation style must be `// @flow strict`

The following patterns are not considered problems:

a;//@flowa;//@flowa;//**@flowa;/* foo @flow bar */a;//@flowa;//@flow//@FLow//@noflowa;// Options: ["always"]// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}a;// Options: ["always",{"annotationStyle":"line"}]//@flow// Options: ["always",{"annotationStyle":"line","strict":true}]//@noflow// Options: ["always",{"annotationStyle":"line","strict":true}]//@flow strict// Options: ["never",{"annotationStyle":"none"}]//@function// Options: ["never"]//@fixable// Options: ["always",{"annotationStyle":"block"}]/*@flow */

require-variable-type

Requires that all variable declarators have type annotations.

Options

You can exclude variables that match a certain regex by usingexcludeVariableMatch.

This excludes all parameters that start with an underscore (_).The default pattern isa^, which doesn't match anything, i.e., all parameters are checked.

{"rules":{"flowtype/require-variable-type":[2,{"excludeVariableMatch":"^_"}]}}

You can choose specific variable types (var,let, andconst) to ignore usingexcludeVariableTypes.

This excludesvar andlet declarations from needing type annotations, but forcesconst declarations to have it.By default, all declarations are checked.

{"rules":{"flowtype/require-variable-type":[2,{"excludeVariableTypes":{"var":true,"let":true,"const":false,}}]}}

The following patterns are considered problems:

varfoo="bar"// Message: Missing "foo" variable type annotation.varfoo :string="bar",bar=1// Message: Missing "bar" variable type annotation.// Options: [{"excludeVariableMatch":"^_"}]var_foo="bar",bar=1// Message: Missing "bar" variable type annotation.// Options: [{"excludeVariableTypes":{"let":false,"var":true}}]varfoo="bar",bar=1;constoob :string="oob";lethey="yah"// Message: Missing "hey" variable type annotation.

The following patterns are not considered problems:

varfoo :string="bar"varfoo :string="bar",bar :number=1// Options: [{"excludeVariableMatch":"^_"}]var_foo="bar",bar :number=1// Options: [{"excludeVariableTypes":{"var":true}}]varfoo="bar",bar=1// Options: [{"excludeVariableTypes":{"let":true,"var":true}}]varfoo="bar",bar=1;constoob :string="oob";lethey="yah"

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:

// Options: ["always"]classFoo{foo:string}// Message: Missing semicolon.// Options: ["never"]classFoo{foo:string;}// Message: Extra semicolon.// Options: []typeFooType={}// Message: Missing semicolon.// Options: ["always"]typeFooType={}// Message: Missing semicolon.// Options: ["never"]typeFooType={};// Message: Extra semicolon.// Options: []opaquetypeFooType={}// Message: Missing semicolon.

The following patterns are not considered problems:

typeFooType={};// Options: ["always"]typeFooType={};// Options: ["always"](foo:string)=>{}// Options: ["always"]classFoo{foo:string;}// Options: ["never"]classFoo{foo:string}// Options: ["always"]typeFooType={a:number; b:string;};// Options: ["never"]typeFooType={a:number; b:string;}// Options: ["never"]typeFooType={}// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeFooType={}opaquetypeFooType={};

sort-keys

The--fix option on the command line automatically fixes problems reported by this rule.

Enforces natural, case-insensitive sorting of Object annotations.

Options

The first option specifies sort order.

  • "asc" (default) - enforce ascending sort order.
  • "desc" - enforce descending sort order.
{"rules":{"flowtype/sort-keys":[2,"asc"]}}

The following patterns are considered problems:

typeFooType={a:number,c:number,b:string}// Message: Expected type annotations to be in ascending order. "b" must be before "c".// Options: ["desc"]typeFooType={a:number,b:number}// Message: Expected type annotations to be in descending order. "b" must be before "a".// Options: ["desc"]typeFooType={b:number,C:number,a:string}// Message: Expected type annotations to be in descending order. "C" must be before "b".// Options: ["asc"]typeFooType={a:number,c:number,C:number,b:string}// Message: Expected type annotations to be in ascending order. "b" must be before "C".// Options: ["asc"]typeFooType={a:number,C:number,c:number,b:string}// Message: Expected type annotations to be in ascending order. "b" must be before "c".// Options: ["asc"]typeFooType={1:number,10:number,2:boolean}// Message: Expected type annotations to be in ascending order. "2" must be before "10".typeFooType={a:number,c:number,b:string}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={a:number,c:number,b:string,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={a:$ReadOnlyArray<number>,c:$ReadOnlyMap<string, number>,b:Map<string,Array<Map<string, number>>>,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={          ...ErrorsInRecursiveGenericTypeArgsButDoesNotFix<{y:boolean,x:string,z:{j:string,l:number,k:boolean,},}>,a:number,c:string,b:Map<string,Array<ErrorsInRecursiveGenericTypeArgsButDoesNotFix<{y:boolean,x:string,z:{j:string,l:number,k:boolean,},}>>>,}// Message: Expected type annotations to be in ascending order. "x" must be before "y".// Message: Expected type annotations to be in ascending order. "k" must be before "l".// Message: Expected type annotations to be in ascending order. "b" must be before "c".// Message: Expected type annotations to be in ascending order. "x" must be before "y".// Message: Expected type annotations to be in ascending order. "k" must be before "l".typeFooType={          ...BPreservesSpreadOrder,          ...APreservesSpreadOrder,c:string,b:number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={          ...BPreservesSpreadSpans,          ...APreservesSpreadSpans,c:string,b:number,          ...CPreservesSpreadSpans,e:string,d:number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".// Message: Expected type annotations to be in ascending order. "d" must be before "e".typeFooType={          ...BPreservesSpreadOrderAndTypeArgs<string, number>,          ...APreservesSpreadOrderAndTypeArgs<number>,c:string,b:number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={/* preserves block comment before spread BType */// preserves line comment before spread BType          .../* preserves comment in spread BType */BType<Generic>/* preserves trailing comment in spread AType */,/* preserves block comment before spread AType */// preserves line comment before spread AType          .../* preserves comment in spread AType */AType/* preserves trailing comment in spread AType */,/* preserves block comment before reordered key "c" */// preserves line comment before reordered key "c"c:/* preserves comment and white space or lack of it */string/* preserves trailing comment for key "c" */,b:number,dWithoutComma:boolean}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={+a:number,c:number,b:string,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={-a:number,c:number,b:string,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={a?:number,c: ?number,b:string,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={a:(number)=>void,c:number,b:(param:string)=>number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={a:number|string|boolean,c:number,b:(param:string)=>number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={c:number,a:number|string|boolean,b:(param:string)=>number,}// Message: Expected type annotations to be in ascending order. "a" must be before "c".typeFooType={c:{z:number,x:string,y:boolean,},a:number|string|boolean,b:(param:string)=>number,}// Message: Expected type annotations to be in ascending order. "x" must be before "z".// Message: Expected type annotations to be in ascending order. "a" must be before "c".typeFooType={c:{z:{j:string,l:number,k:boolean,},x:string,y:boolean,},a:number|string|boolean,b:(param:string)=>number,}// Message: Expected type annotations to be in ascending order. "k" must be before "l".// Message: Expected type annotations to be in ascending order. "x" must be before "z".// Message: Expected type annotations to be in ascending order. "a" must be before "c".typeFooType={+c:number,-b:number,a:number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".// Message: Expected type annotations to be in ascending order. "a" must be before "b".typeFooType={|+c:number,-b:number,a:number,|}// Message: Expected type annotations to be in ascending order. "b" must be before "c".// Message: Expected type annotations to be in ascending order. "a" must be before "b".typeFooType={a(number):void,c:number,b(param:string):number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={a:number|string|boolean,c:number,b(param:string):number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".typeFooType={c:number,a:number|string|boolean,b(param:string):number,}// Message: Expected type annotations to be in ascending order. "a" must be before "c".typeFooType={c:{z:number,x:string,y:boolean,},a:number|string|boolean,b(param:string):number,}// Message: Expected type annotations to be in ascending order. "x" must be before "z".// Message: Expected type annotations to be in ascending order. "a" must be before "c".typeFooType={c:{z:{j:string,l:number,k:boolean,},x:string,y:boolean,},a:number|string|boolean,b(param:string):number,}// Message: Expected type annotations to be in ascending order. "k" must be before "l".// Message: Expected type annotations to be in ascending order. "x" must be before "z".// Message: Expected type annotations to be in ascending order. "a" must be before "c".typeFooType={/* preserves block comment before a */a:number|string|boolean,/* preserves block comment before c */c:number,/* preserves block comment before b */b(param:string):number,}// Message: Expected type annotations to be in ascending order. "b" must be before "c".exporttypeGroupOrdersResponseType={|isSuccess:boolean,code:number,message?:string,errorMessage:string,result:{|OrderNumber:string,Orders:GroupOrderSummaryType[],PlacedOn:string,Status:string,ReturnText:string,IncludesLegacyOrder:boolean|}|};// Message: Expected type annotations to be in ascending order. "code" must be before "isSuccess".// Message: Expected type annotations to be in ascending order. "errorMessage" must be before "message".// Message: Expected type annotations to be in ascending order. "ReturnText" must be before "Status".// Message: Expected type annotations to be in ascending order. "IncludesLegacyOrder" must be before "ReturnText".

The following patterns are not considered problems:

typeFooType={a:number}typeFooType={a:number,b:number,c:(boolean|number)}typeFooType={a:string,b:foo,C:number}typeFooType={1:number,2:boolean,10:number}// Options: ["desc"]typeFooType={c:number,b:number,a:number}// Options: ["desc"]typeFooType={C:number,b:string,a:{}}// Options: ["desc"]typeFooType={10:number,2:number,1:boolean}// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeFooType={b:number,a:number}typeFooType={a:string,b():number,c:boolean}typeFooType={a():string,b:number,c:boolean}

sort-type-union-intersection-members

The--fix option on the command line automatically fixes problems reported by this rule.

Enforces that members of a type union/intersection are sorted alphabetically.

Options

You can specify the sort order usingorder.

  • "asc" (default) - enforce ascending sort order.
  • "desc" - enforce descending sort order.
{"rules":{"flowtype/sort-type-union-intersection-members":[2,{"order":"asc"}]}}

You can disable checking intersection types usingcheckIntersections.

  • true (default) - enforce sort order of intersection members.
  • false - do not enforce sort order of intersection members.
{"rules":{"flowtype/sort-type-union-intersection-members":[2,{"checkIntersections":true}]}}

You can disable checking union types usingcheckUnions.

  • true (default) - enforce sort order of union members.
  • false - do not enforce sort order of union members.
{"rules":{"flowtype/sort-type-union-intersection-members":[2,{"checkUnions":true}]}}

You can specify the ordering of groups usinggroupOrder.

Each member of the type is placed into a group, and then the rule sorts alphabetically within each group.The ordering of groups is determined by this option.

  • keyword - Keyword types (any,string, etc)
  • named - Named types (A,A['prop'],B[],Array<C>)
  • literal - Literal types (1,'b',true, etc)
  • function - Function types (() => void)
  • object - Object types ({ a: string },{ [key: string]: number })
  • tuple - Tuple types ([A, B, C])
  • intersection - Intersection types (A & B)
  • union - Union types (A | B)
  • nullish -null andundefined
{"rules":{"flowtype/sort-type-union-intersection-members":[2,{"groupOrder":['keyword','named','literal','function','object','tuple','intersection','union','nullish',]}]}}

The following patterns are considered problems:

typeT1=B|A;// Message: Expected union members to be in ascending order. "A" should be before "B".typeT2={b:string}&{a:string};// Message: Expected intersection members to be in ascending order. "{ a: string }" should be before "{ b: string }".typeT3=[1,2,4]&[1,2,3];// Message: Expected intersection members to be in ascending order. "[1, 2, 3]" should be before "[1, 2, 4]".typeT4=|[1,2,4]|[1,2,3]|{b:string}|{a:string}|(()=>void)|(()=>string)|'b'|'a'|'b'|'a'|string[]|number[]|B|A|string|any;// Message: Expected union members to be in ascending order. "[1, 2, 3]" should be before "[1, 2, 4]".// Message: Expected union members to be in ascending order. "{ b: string }" should be before "[1, 2, 3]".// Message: Expected union members to be in ascending order. "{ a: string }" should be before "{ b: string }".// Message: Expected union members to be in ascending order. "() => void" should be before "{ a: string }".// Message: Expected union members to be in ascending order. "() => string" should be before "() => void".// Message: Expected union members to be in ascending order. "'b'" should be before "() => string".// Message: Expected union members to be in ascending order. "'a'" should be before "'b'".// Message: Expected union members to be in ascending order. "'b'" should be before "'a'".// Message: Expected union members to be in ascending order. "'a'" should be before "'b'".// Message: Expected union members to be in ascending order. "string[]" should be before "'a'".// Message: Expected union members to be in ascending order. "number[]" should be before "string[]".// Message: Expected union members to be in ascending order. "B" should be before "number[]".// Message: Expected union members to be in ascending order. "A" should be before "B".// Message: Expected union members to be in ascending order. "string" should be before "A".// Message: Expected union members to be in ascending order. "any" should be before "string".

The following patterns are not considered problems:

typeT1=A|B;typeT2={a:string}&{b:string};typeT3=[1,2,3]&[1,2,4];typeT4=|any|string|A|B|number[]|string[]|'a'|'a'|'b'|'b'|(()=>string)|(()=>void)|{a:string}|{b:string}|[1,2,3]|[1,2,4];

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.

Options

This rule has a string argument.

  • "always" (default): Require a space after the type annotation colon (e.g. foo: BarType).
  • "never": Require no spaces after the type annotation colon (e.g. foo:BarType).

This rule has an option object.

  • "allowLineBreak" - Allow a line break to count as a space following the annotation colon.
    • "true": Enable
    • "false": Disable

{"rules": {"flowtype/space-after-type-colon": [2,"always", {"allowLineBreak": false}]}}

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 1 space after "foo" parameter type annotation colon.// Options: ["always"](foo:(()=>void))=>{}// Message: There must be a space after "foo" parameter type annotation colon.// Options: ["never"](foo:(()=>void))=>{}// Message: There must be no space after "foo" parameter type annotation colon.// Options: ["always"](foo:(()=>void))=>{}// Message: There must be 1 space after "foo" parameter type annotation colon.({ lorem, ipsum, dolor} :SomeType)=>{}// Message: There must be 1 space after "{ lorem, ipsum, dolor }" parameter type annotation colon.(foo:{a:string,b:number})=>{}// Message: There must be a space after "foo" parameter type annotation colon.({ a, b} :{a:string,b:number})=>{}// Message: There must be a space after "{ a, b }" parameter type annotation colon.([a,b] :string[])=>{}// Message: There must be a space after "[ a, b ]" parameter type annotation colon.(i?:number)=>{}// Message: There must be a space after "i" parameter type annotation colon.(i?:number)=>{}// Message: There must be 1 space after "i" parameter type annotation colon.// Options: ["never"](i?:number)=>{}// Message: There must be no space after "i" parameter type annotation colon.(foo:{a:string,b:number})=>{}// Message: There must not be a line break after "foo" parameter type annotation colon.(foo:{a:string,b:number})=>{}// Message: There must not be a line break after "foo" parameter type annotation colon.(foo:{a:string,b:number})=>{}// Message: There must not be a line break after "foo" parameter type annotation colon.// Options: ["always"]():Object=>{}// Message: There must be a space after return type colon.// Options: ["never"]():Object=>{}// Message: There must be no space after return type colon.// Options: ["always"]():Object=>{}// Message: There must be 1 space after return type colon.// Options: ["always"]():(()=>void)=>{}// Message: There must be a space after return type colon.// Options: ["never"]():(()=>void)=>{}// Message: There must be no space after return type colon.// Options: ["always"]():(()=>void)=>{}// Message: There must be 1 space after return type colon.// Options: ["never"]exportdefaultfunction(foo:string){}// Message: There must be no space after "foo" parameter type annotation colon.// Options: ["never"]functionfoo(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.functionfoo(foo:string){}// Message: There must be a space after "foo" parameter type annotation colon.asyncfunctionfoo({ lorem, ipsum, dolor}:SomeType){}// Message: There must be a space after "{ lorem, ipsum, dolor }" parameter type annotation colon.functionx(i?:number){}// Message: There must be a space after "i" parameter type annotation colon.functionx(i?:number){}// Message: There must be 1 space after "i" parameter type annotation colon.// Options: ["never"]functionx(i?:number){}// Message: There must be no space after "i" parameter type annotation colon.functiona():x{}// Message: There must be a space after return type colon.// Options: ["always"]functiona():x{}// Message: There must be 1 space after return type colon.// Options: ["never"]functiona():x{}// Message: There must be no space after return type colon.typeX=(foo:number)=>string// Message: There must be a space after "foo" parameter type annotation colon.// Options: ["never"]typeX=(foo:number)=>string// Message: There must be no space after "foo" parameter type annotation colon.typeX=(foo:number)=>string// Message: There must be 1 space after "foo" parameter type annotation colon.typeX=(foo:?number)=>string// Message: There must be a space after "foo" parameter type annotation colon.typeX=(foo:(number))=>string// Message: There must be a space after "foo" parameter type annotation colon.typeX=(foo:((number)))=>string// Message: There must be a space after "foo" parameter type annotation colon.typeX=(foo:((number)))=>string// Message: There must be 1 space after "foo" parameter type annotation colon.// Options: ["never"]typeX=(foo:((number)))=>string// Message: There must be no space after "foo" parameter type annotation colon.typeX=(foo:?(number))=>string// Message: There must be a space after "foo" parameter type annotation colon.typeTArrayPredicate=(el:T,i?:number)=>boolean// Message: There must be a space after "i" parameter type annotation colon.typeTArrayPredicate=(el:T,i?:number)=>boolean// Message: There must be 1 space after "i" parameter type annotation colon.// Options: ["never"]typeTArrayPredicate=(el:T,i?:number)=>boolean// Message: There must be no space after "i" parameter type annotation colon.classX{foo:string}// Message: There must be a space after "foo" class property type annotation colon.// Options: ["never"]classX{foo:string}// Message: There must be no space after "foo" class property type annotation colon.classX{foo:?string}// Message: There must be a space after "foo" class property type annotation colon.// Options: ["never"]classX{foo: ?string}// Message: There must be no space after "foo" class property type annotation colon.classX{staticfoo:number}// Message: There must be a space after "foo" class property type annotation colon.// Options: ["never"]classX{staticfoo:number}// Message: There must be no space after "foo" class property type annotation colon.classX{staticfoo :number}// Message: There must be a space after "foo" class property type annotation colon.// Options: ["never"]classX{staticfoo :number}// Message: There must be no space after "foo" class property type annotation colon.declareclassX{staticfoo:number}// Message: There must be a space after "foo" type annotation colon.// Options: ["never"]declareclassX{staticfoo:number}// Message: There must be no space after "foo" type annotation colon.declareclassX{staticfoo :number}// Message: There must be a space after "foo" type annotation colon.// Options: ["never"]declareclassX{staticfoo :number}// Message: There must be no space after "foo" type annotation colon.classX{+foo:string}// Message: There must be a space after "foo" class property type annotation colon.classX{+foo:string}// Message: There must be 1 space after "foo" class property type annotation colon.// Options: ["never"]classX{+foo:string}// Message: There must be no space after "foo" class property type annotation colon.classX{static+foo:string}// Message: There must be a space after "foo" class property type annotation colon.classX{static+foo:string}// Message: There must be 1 space after "foo" class property type annotation colon.// Options: ["never"]classX{static+foo:string}// Message: There must be no space after "foo" class property type annotation colon.typeX={foo:string}// Message: There must be a space after "foo" type annotation colon.// Options: ["always"]typeX={foo:string}// Message: There must be a space after "foo" type annotation colon.// Options: ["never"]typeX={foo:string}// Message: There must be no space after "foo" type annotation colon.typeX={foo:string}// Message: There must be 1 space after "foo" type annotation colon.typeX={foo?:string}// Message: There must be a space after "foo" type annotation colon.// Options: ["never"]typeX={foo?:string}// Message: There must be no space after "foo" type annotation colon.typeX={foo?:?string}// Message: There must be a space after "foo" type annotation colon.typeX={foo?:  ?string}// Message: There must be 1 space after "foo" type annotation colon.typeFoo={barType:(string|()=>void)}// Message: There must be a space after "barType" type annotation colon.typeFoo={barType:(((string|()=>void)))}// Message: There must be a space after "barType" type annotation colon.// Options: ["never"]typeFoo={barType:(string|()=>void)}// Message: There must be no space after "barType" type annotation colon.typeFoo={barType:(string|()=>void)}// Message: There must be 1 space after "barType" type annotation colon.typeFoo={barType:((string|()=>void))}// Message: There must be 1 space after "barType" type annotation colon.typeX={get:()=>A;}// Message: There must be a space after "get" type annotation colon.typeX={get:<X>() =>A;}// Message: There must be a space after "get" type annotation colon.// Options: ["never"]typeX={get:()=>A;}// Message: There must be no space after "get" type annotation colon.// Options: ["never"]typeX={get:<X>() =>A;}// Message: There must be no space after "get" type annotation colon.typeX={get:()=>A;}// Message: There must be 1 space after "get" type annotation colon.typeX={get:<X>() =>A;}// Message: There must be 1 space after "get" type annotation colon.typeX={+foo:string}// Message: There must be a space after "foo" type annotation colon.typeX={+foo:string}// Message: There must be 1 space after "foo" type annotation colon.// Options: ["never"]typeX={+foo:string}// Message: There must be no space after "foo" type annotation colon.typeX={+foo?:string}// Message: There must be a space after "foo" type annotation colon.typeX={+foo?:string}// Message: There must be 1 space after "foo" type annotation colon.// Options: ["never"]typeX={+foo?:string}// Message: There must be no space after "foo" type annotation colon.// Options: ["always"]typeX={[a:b]:c}// Message: There must be a space after type annotation colon.// Options: ["never"]typeX={[a:b]:c}// Message: There must be no space after type annotation colon.// Options: ["always"]typeX={[a:b]:c}// Message: There must be 1 space after type annotation colon.// Options: ["always"]typeX={+[a:b]:c}// Message: There must be a space after type annotation colon.// Options: ["never"]typeX={+[a:b]:c}// Message: There must be no space after type annotation colon.// Options: ["always"]typeX={+[a:b]:c}// Message: There must be 1 space after type annotation colon.// Options: ["always"]typeX={[a:b]:c}// Message: There must be a space after type annotation colon.// Options: ["never"]typeX={[a:b]:c}// Message: There must be no space after type annotation colon.// Options: ["always"]typeX={[a:b]:c}// Message: There must be 1 space after type annotation colon.// Options: ["always"]typeX={[a:b]:c}// Message: There must be a space after type annotation colon.// Message: There must be a space after type annotation colon.// Options: ["never"]typeX={[a:b]:c}// Message: There must be no space after type annotation colon.// Message: There must be no space after type annotation colon.// Options: ["always"]typeX={[a:b]:c}// Message: There must be 1 space after type annotation colon.// Message: There must be 1 space after type annotation colon.// Options: ["always"]typeX={[a:(b)]:(c)}// Message: There must be a space after type annotation colon.// Message: There must be a space after type annotation colon.// Options: ["never"]typeX={[a:(b)]:(c)}// Message: There must be no space after type annotation colon.// Message: There must be no space after type annotation colon.// Options: ["never"]constx=({}:{})// Message: There must be no space after type cast colon.// Options: ["always"]constx=({}:{})// Message: There must be a space after type cast colon.// Options: ["always"]constx=({}:{})// Message: There must be 1 space after type cast colon.// Options: ["never"]((x):(string))// Message: There must be no space after type cast colon.// Options: ["always"]((x):(string))// Message: There must be a space after type cast colon.// Options: ["always"]((x):(string))// Message: There must be 1 space after type cast colon.// Options: ["always"]constx:number=7;// Message: There must be a space after const type annotation colon.// Options: ["always"]letx:number=42;// Message: There must be a space after let type annotation colon.// Options: ["always"]varx:number=42;// Message: There must be a space after var type annotation colon.

The following patterns are not considered problems:

(foo)=>{}(foo:string)=>{}(foo:(string|number))=>{}// Options: ["never"](foo:string)=>{}// Options: ["always"](foo:string)=>{}// Options: ["never"](foo:(()=>void))=>{}// Options: ["always"](foo:(()=>void))=>{}({ lorem, ipsum, dolor}:SomeType)=>{}(foo:{a:string,b:number})=>{}({ a, b}: ?{a:string,b:number})=>{}([a,b]:string[])=>{}(i?:number)=>{}// Options: ["never"](i?:number)=>{}// Options: ["always",{"allowLineBreak":true}](foo:{a:string,b:number})=>{}// Options: ["always",{"allowLineBreak":true}](foo:{a:string,b:number})=>{}// Options: ["never"]():Object=>{}// Options: ["always"]():Object=>{}// Options: ["never"]():(number|string)=>{}// Options: ["always"]():(number|string)=>{}// Options: ["never"]():number|string=>{}// Options: ["always"]():number|string=>{}// Options: ["never"]():(()=>void)=>{}// Options: ["always"]():(()=>void)=>{}// Options: ["never"]():(()=>void)=>{}// Options: ["always"]():(()=>void)=>{}():{a:number,b:string}=>{}// Options: ["never"]() :{a:number,b:string}=>{}functionx(foo:string){}classFoo{constructor(foo:string){}}// Options: ["never"]functionx(foo:string){}// Options: ["never"]classFoo{constructor(foo:string){}}asyncfunctionfoo({ lorem, ipsum, dolor}:SomeType){}functionx({ a, b}:{a:string,b:number}){}functionx(i?:number){}// Options: ["never"]functionx(i?:number){}functiona():x{}// Options: ["never"]functiona():x{}functiona():(number|string){}// Options: ["never"]functiona() :(number|string){}typeX=(foo:number)=>string;typeX=(foo :number)=>string;typeX=(foo: ?number)=>string;typeX=(foo? : ?number)=>string;typeX=(foo: ?{x:number})=>string;// Options: ["never"]typeX=(foo:number)=>string;// Options: ["never"]typeX=(foo:?{x:number})=>string;typeX=(foo:(number))=>stringtypeX=(foo:((number)))=>string// Options: ["never"]typeX=(foo:((number)))=>stringtypeX= ?(foo:((number)))=>string// Options: ["never"]typeX= ?(foo:((number)))=>stringtypeTArrayPredicate=(el:T,i?:number)=>boolean// Options: ["never"]typeTArrayPredicate=(el:T,i?:number)=>booleantypeX=(number)=>string;typeX=(?number)=>string;typeX=number=>string;typeX= ?number=>string;typeX=({foo:bar})=>string;// Options: ["always"]typeX=(number)=>string;// Options: ["always"]typeX=(?number)=>string;// Options: ["always"]typeX=number=>string;// Options: ["always"]typeX= ?number=>string;// Options: ["always"]typeX=({foo:bar})=>string;classFoo{bar}classFoo{bar=3}classFoo{bar:string}classFoo{bar: ?string}// Options: ["never"]classFoo{bar:string}// Options: ["never"]classFoo{bar:?string}classX{staticfoo :number}// Options: ["never"]classX{staticfoo :number}declareclassX{staticfoo :number}// Options: ["never"]declareclassX{staticfoo :number}classX{+foo:string}classX{static+foo:string}// Options: ["never"]classX{+foo:string}// Options: ["never"]classX{static+foo:string}typeX={foo:string}// Options: ["never"]typeX={foo:string}typeX={foo?:string}typeX={foo?: ?string}// Options: ["never"]typeX={foo?:?string}typeFoo={barType:(string|()=>void)}typeFoo={barType:((string|()=>void))}// Options: ["never"]typeFoo={barType:(string|()=>void)}// Options: ["never"]typeFoo={barType:((string|()=>void))}typeX={get():A;}typeX={ get<X>():A;}// Options: ["never"]typeX={get():A;}// Options: ["never"]typeX={ get<X>():A;}typeX={get:()=>A;}typeX={get:<X>() =>A;}// Options: ["never"]typeX={get:()=>A;}// Options: ["never"]typeX={get:<X>()=>A;}typeX={+foo:string}typeX={+foo?:string}// Options: ["never"]typeX={+foo:string}// Options: ["never"]typeX={+foo?:string}// Options: ["always"]typeX={[a:b]:c}// Options: ["never"]typeX={[a:b]:c}// Options: ["always"]typeX={+[a:b]:c}// Options: ["never"]typeX={+[a:b]:c}// Options: ["always"]typeX={[string]:c}// Options: ["never"]typeX={[string]:c}// Options: ["never"]constx=({}:{})// Options: ["always"]constx=({}:{})// Options: ["never"]((x):(string))// Options: ["always"]((x):(string))// Options: ["always"]constx:number=7;// Options: ["always"]letx:number=42;// Options: ["always"]varx:number=42;

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:

typeX=Promise<string>// Message: There must be no space before "Promise" generic type annotation bracket// Options: ["never"]typeX=Promise<string>// Message: There must be no space before "Promise" generic type annotation brackettypeX=Promise<string>// Message: There must be no space before "Promise" generic type annotation bracket// Options: ["always"]typeX=Promise<string>// Message: There must be a space before "Promise" generic type annotation bracket// Options: ["always"]typeX=Promise<string>// Message: There must be one space before "Promise" generic type annotation bracket

The following patterns are not considered problems:

typeX=Promise<string>// Options: ["always"]typeX=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:

// Options: ["never"](foo :string)=>{}// Message: There must be no space before "foo" parameter type annotation colon.// 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.// 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.// Options: ["always"](foo  ?:string)=>{}// Message: There must be a space before "foo" parameter type annotation colon.({ lorem, ipsum, dolor} :SomeType)=>{}// Message: There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.(foo :{a:string,b:number})=>{}// Message: There must be no space before "foo" parameter type annotation colon.({ a, b} :{a:string,b:number})=>{}// Message: There must be no space before "{ a, b }" parameter type annotation colon.([a,b] :string[])=>{}// Message: There must be no space before "[ a, b ]" parameter type annotation colon.() :x=>{}// Message: There must be no space before return type colon.// Options: ["always"]():x=>{}// Message: There must be a space before return type colon.// Options: ["always"]()  :x=>{}// Message: There must be 1 space before return type colon.functionx(foo :string){}// Message: There must be no space before "foo" parameter type annotation colon.// Options: ["always"]functionx(foo:string){}// Message: There must be a space before "foo" parameter type annotation colon.varx=function(foo :string){}// Message: There must be no space before "foo" parameter type annotation colon.// Options: ["always"]varx=function(foo:string){}// Message: There must be a space before "foo" parameter type annotation colon.classFoo{constructor(foo :string){}}// Message: There must be no space before "foo" parameter type annotation colon.// Options: ["always"]classFoo{constructor(foo:string){}}// Message: There must be a space before "foo" parameter type annotation colon.asyncfunctionfoo({ lorem, ipsum, dolor} :SomeType){}// Message: There must be no space before "{ lorem, ipsum, dolor }" parameter type annotation colon.functiona() :x{}// Message: There must be no space before return type colon.// Options: ["always"]functiona():x{}// Message: There must be a space before return type colon.// Options: ["always"]functiona()  :x{}// Message: There must be 1 space before return type colon.typeX=(foo :string)=>string;// Message: There must be no space before "foo" parameter type annotation colon.// Options: ["always"]typeX=(foo:string)=>string;// Message: There must be a space before "foo" parameter type annotation colon.// Options: ["always"]typeX=(foo  :string)=>string;// Message: There must be 1 space before "foo" parameter type annotation colon.typeX=(foo? :string)=>string;// Message: There must be no space before "foo" parameter type annotation colon.typeX=(foo?     :string)=>string;// Message: There must be no space before "foo" parameter type annotation colon.// Options: ["always"]typeX=(foo?:string)=>string;// Message: There must be a space before "foo" parameter type annotation colon.typeX=(foo? :?string)=>string;// Message: There must be no space before "foo" parameter type annotation colon.classX{foo :string}// Message: There must be no space before "foo" class property type annotation colon.// Options: ["always"]classX{foo:string}// Message: There must be a space before "foo" class property type annotation colon.classX{foo :?string}// Message: There must be no space before "foo" class property type annotation colon.// Options: ["always"]classX{foo: ?string}// Message: There must be a space before "foo" class property type annotation colon.classX{staticfoo :number}// Message: There must be no space before "foo" class property type annotation colon.classX{staticfoo :number}// Message: There must be no space before "foo" class property type annotation colon.// Options: ["always"]classX{staticfoo:number}// Message: There must be a space before "foo" class property type annotation colon.// Options: ["always"]classX{staticfoo:number}// Message: There must be a space before "foo" class property type annotation colon.declareclassFoo{staticbar :number;}// Message: There must be no space before "bar" type annotation colon.declareclassFoo{staticbar :number;}// Message: There must be no space before "bar" type annotation colon.// Options: ["always"]declareclassFoo{staticbar:number;}// Message: There must be a space before "bar" type annotation colon.// Options: ["always"]declareclassFoo{staticbar:number;}// Message: There must be a space before "bar" type annotation colon.// Options: ["always"]classX{+foo:string}// Message: There must be a space before "foo" class property type annotation colon.// Options: ["always"]classX{+foo  :string}// Message: There must be 1 space before "foo" class property type annotation colon.// Options: ["never"]classX{+foo :string}// Message: There must be no space before "foo" class property type annotation colon.// Options: ["always"]classX{static+foo:string}// Message: There must be a space before "foo" class property type annotation colon.// Options: ["always"]classX{static+foo  :string}// Message: There must be 1 space before "foo" class property type annotation colon.// Options: ["never"]classX{static+foo :string}// Message: There must be no space before "foo" class property type annotation colon.typeX={foo :string}// Message: There must be no space before "foo" type annotation colon.// Options: ["never"]typeX={foo :string}// Message: There must be no space before "foo" type annotation colon.// Options: ["always"]typeX={foo:string}// Message: There must be a space before "foo" type annotation colon.// Options: ["always"]typeX={foo  :string}// Message: There must be 1 space before "foo" type annotation colon.typeX={foo? :string}// Message: There must be no space before "foo" type annotation colon.// Options: ["always"]typeX={foo?:string}// Message: There must be a space before "foo" type annotation colon.// Options: ["always"]typeX={foo?  :string}// Message: There must be 1 space before "foo" type annotation colon.// Options: ["always"]typeX={foo   ?:string}// Message: There must be a space before "foo" type annotation colon.// Options: ["always"]typeX={+foo:string}// Message: There must be a space before "foo" type annotation colon.// Options: ["always"]typeX={+foo  :string}// Message: There must be 1 space before "foo" type annotation colon.// Options: ["never"]typeX={+foo :string}// Message: There must be no space before "foo" type annotation colon.// Options: ["always"]typeX={+foo?:string}// Message: There must be a space before "foo" type annotation colon.// Options: ["always"]typeX={+foo?  :string}// Message: There must be 1 space before "foo" type annotation colon.// Options: ["never"]typeX={+foo? :string}// Message: There must be no space before "foo" type annotation colon.// Options: ["always"]typeX={[a:b] :c}// Message: There must be a space before type annotation colon.// Options: ["never"]typeX={[a :b]:c}// Message: There must be no space before type annotation colon.// Options: ["always"]typeX={[a  :b] :c}// Message: There must be 1 space before type annotation colon.// Options: ["always"]typeX={+[a:b] :c}// Message: There must be a space before type annotation colon.// Options: ["never"]typeX={+[a :b]:c}// Message: There must be no space before type annotation colon.// Options: ["always"]typeX={+[a  :b] :c}// Message: There must be 1 space before type annotation colon.// Options: ["always"]typeX={[a :b]:c}// Message: There must be a space before type annotation colon.// Options: ["never"]typeX={[a:b] :c}// Message: There must be no space before type annotation colon.// Options: ["always"]typeX={[a :b]  :c}// Message: There must be 1 space before type annotation colon.// Options: ["always"]typeX={[a:b]:c}// Message: There must be a space before type annotation colon.// Message: There must be a space before type annotation colon.// Options: ["never"]typeX={[a :b] :c}// Message: There must be no space before type annotation colon.// Message: There must be no space before type annotation colon.// Options: ["always"]typeX={[a  :b]  :c}// Message: There must be 1 space before type annotation colon.// Message: There must be 1 space before type annotation colon.// Options: ["always"]typeX={[a:(b)]:(c)}// Message: There must be a space before type annotation colon.// Message: There must be a space before type annotation colon.// Options: ["never"]typeX={[a :(b)] :(c)}// Message: There must be no space before type annotation colon.// Message: There must be no space before type annotation colon.// Options: ["never"]constx=({} :{})// Message: There must be no space before type cast colon.// Options: ["always"]constx=({}:{})// Message: There must be a space before type cast colon.// Options: ["always"]constx=({}  :{})// Message: There must be 1 space before type cast colon.// Options: ["never"]((x) :string)// Message: There must be no space before type cast colon.// Options: ["always"]((x):string)// Message: There must be a space before type cast colon.// Options: ["always"]((x)  :string)// Message: There must be 1 space before type cast colon.// Options: ["always"]constx:number=7;// Message: There must be a space before const type annotation colon.// Options: ["always"]letx:number=42;// Message: There must be a space before let type annotation colon.// Options: ["always"]varx:number=42;// Message: There must be a space before var type annotation colon.

The following patterns are not considered problems:

(foo)=>{}(foo:string)=>{}(foo?:string)=>{}(foo ?:string)=>{}// Options: ["never"](foo:string)=>{}// Options: ["always"](foo :string)=>{}// Options: ["always"](foo? :string)=>{}// Options: ["always"](foo ? :string)=>{}// Options: ["always"](foo  ? :string)=>{}({ lorem, ipsum, dolor}:SomeType)=>{}(foo:{a:string,b:number})=>{}({ a, b}: ?{a:string,b:number})=>{}():{a:number,b:string}=>{}// Options: ["always"]() :{a :number,b :string}=>{}([a,b]:string[])=>{}():x=>{}// Options: ["always"]() :x=>{}():(number|string)=>{}// Options: ["always"]() :(number|string)=>{}functionx(foo:string){}// Options: ["always"]functionx(foo :string){}varx=function(foo:string){}// Options: ["always"]varx=function(foo :string){}classX{foo({ bar}:Props=this.props){}}classFoo{constructor(foo:string){}}// Options: ["always"]classFoo{constructor(foo :string){}}asyncfunctionfoo({ lorem, ipsum, dolor}:SomeType){}functionx({ a, b}:{a:string,b:number}){}functiona():x{}// Options: ["always"]functiona() :x{}functiona():(number|string){}// Options: ["always"]functiona() :(number|string){}typeX=(foo:string)=>number;typeX=(foo:string)=>number;typeX=(foo: ?string)=>number;typeX=(foo?:string)=>number;typeX=(foo?: ?string)=>number;typeX=(foo   ?:string)=>number;// Options: ["always"]typeX=(foo? :string)=>number// Options: ["always"]typeX=(foo? : ?string)=>numbertypeX=(number)=>string;typeX=(?number)=>string;typeX=number=>string;typeX= ?number=>string;typeX=({foo:bar})=>string;// Options: ["always"]typeX=(number)=>string;// Options: ["always"]typeX=(?number)=>string;// Options: ["always"]typeX=number=>string;// Options: ["always"]typeX= ?number=>string;// Options: ["always"]typeX=({foo :bar})=>string;classFoo{bar}classFoo{bar=3}classFoo{bar:string}classFoo{bar: ?string}classFoo{bar:?string}// Options: ["always"]classFoo{bar :string}classX{staticfoo:number}classX{staticfoo:number}// Options: ["always"]classX{staticfoo :number}// Options: ["always"]classX{staticfoo :number}declareclassFoo{staticbar:number;}// Options: ["always"]declareclassFoo{staticbar :number;}declareclassFoo{staticbar:number;}// Options: ["always"]declareclassFoo{staticbar :number;}classX{+foo:string}classX{static+foo:string}// Options: ["always"]classX{+foo :string}// Options: ["always"]classX{static+foo :string}typeX={foo:string}// Options: ["always"]typeX={foo :string}typeX={foo?:string}typeX={foo   ?:string}// Options: ["always"]typeX={foo? :string}typeX={+foo:string}typeX={+foo?:string}// Options: ["always"]typeX={+foo :string}// Options: ["always"]typeX={+foo? :string}// Options: ["always"]typeX={[a :b] :c}// Options: ["never"]typeX={[a:b]:c}// Options: ["always"]typeX={[string] :c}// Options: ["never"]typeX={[string]:c}// Options: ["always"]typeX={+[a :b] :c}// Options: ["never"]typeX={+[a:b]:c}// Options: ["always"]typeX={[a :(b)] :(c)}// Options: ["never"]typeX={[a:(b)]:(c)}// Options: ["never"]constx=({}:{})// Options: ["always"]constx=({} :{})// Options: ["never"]((x):string)// Options: ["always"]((x) :string)// Options: ["always"]constx :number=7;// Options: ["always"]letx :number=42;// Options: ["always"]varx :number=42;

spread-exact-type

Enforce object types, that are spread to be exact type explicitly.

The following patterns are considered problems:

typebar={...{test:string}}// Message: Use $Exact to make type spreading safe.typefoo={test:number};typebar={...foo}// Message: Use $Exact to make type spreading safe.

The following patterns are not considered problems:

typebar={...$Exact<{test:string}>}typefoo={test:number};typebar={...$Exact<foo>}

type-id-match

Enforces a consistent naming pattern for type aliases.

Options

This rule requires a text RegExp:

{"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:

opaquetypefoo={};// Message: Type identifier 'foo' does not match pattern '/^([A-Z][a-z0-9]*)+Type$/u'.typefoo={};// Message: Type identifier 'foo' does not match pattern '/^([A-Z][a-z0-9]*)+Type$/u'.// Options: ["^foo$"]typeFooType={};// Message: Type identifier 'FooType' does not match pattern '/^foo$/u'.

The following patterns are not considered problems:

typeFooType={};// Options: ["^foo$"]typefoo={};// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typefoo={};

type-import-style

The--fix option on the command line automatically fixes problems reported by this rule.

Enforces a particular style for type imports:

// 'identifier' styleimport {type T, type U, type V} from '...';// 'declaration' styleimport type {T, U, V} from '...';

Options

The rule has a string option:

  • "identifier" (default): Enforces that type imports are all in the'identifier' style.
  • "declaration": Enforces that type imports are all in the 'declaration'style.

This rule has an object option:

  • ignoreTypeDefault - iftrue, when in "identifier" mode, default type imports will be ignored. Default isfalse.

The following patterns are considered problems:

importtype{A,B}from'a';// Message: Unexpected "import type"// Options: ["identifier"]importtype{A,B}from'a';// Message: Unexpected "import type"// Options: ["identifier"]importtype{A,BasC}from'a';// Message: Unexpected "import type"// Options: ["identifier"]importtypeAfrom'a';// Message: Unexpected "import type"// Options: ["declaration"]import{typeA,typeB}from'a';// Message: Unexpected type import// Message: Unexpected type import

The following patterns are not considered problems:

import{typeA,typeB}from'a';// Options: ["identifier"]import{typeA,typeB}from'a';// Options: ["declaration"]importtype{A,B}from'a';// Options: ["identifier"]importtypeof*asAfrom'a';// Options: ["identifier",{"ignoreTypeDefault":true}]importtypeAfrom'a';// Options: ["identifier"]declaremodule"m"{importtypeAfrom'a';}

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:

typeX=string|number;// Message: There must be a space before union type annotation separator// Options: ["always"]typeX=string|number;// Message: There must be a space before union type annotation separatortypeX=string|number;// Message: There must be a space after union type annotation separatortypeX=string|number;// Message: There must be a space before union type annotation separator// Message: There must be a space after union type annotation separatortypeX={x:string}|{y:number};// Message: There must be a space before union type annotation separator// Message: There must be a space after union type annotation separatortypeX=string|number|boolean;// Message: There must be a space after union type annotation separatortypeX=string|number|boolean;// Message: There must be a space before union type annotation separator// Message: There must be a space after union type annotation separator// Message: There must be a space before union type annotation separator// Message: There must be a space after union type annotation separatortypeX=(string)|number;// Message: There must be a space before union type annotation separatortypeX=((string))|(number|foo);// Message: There must be a space before union type annotation separator// Message: There must be a space after union type annotation separator// Options: ["never"]typeX=string|number;// Message: There must be no space before union type annotation separator// Options: ["never"]typeX=string|number;// Message: There must be no space after union type annotation separatortypeX=string&number;// Message: There must be a space before intersection type annotation separator// Options: ["always"]typeX=string&number;// Message: There must be a space before intersection type annotation separatortypeX=string&number;// Message: There must be a space after intersection type annotation separatortypeX={x:string}&{y:number};// Message: There must be a space before intersection type annotation separator// Message: There must be a space after intersection type annotation separatortypeX=string&number;// Message: There must be a space before intersection type annotation separator// Message: There must be a space after intersection type annotation separatortypeX=string&number&boolean;// Message: There must be a space after intersection type annotation separatortypeX=string&number&boolean;// Message: There must be a space before intersection type annotation separator// Message: There must be a space after intersection type annotation separator// Message: There must be a space before intersection type annotation separator// Message: There must be a space after intersection type annotation separatortypeX=(string)&number;// Message: There must be a space before intersection type annotation separatortypeX=((string))&(number&foo);// Message: There must be a space before intersection type annotation separator// Message: There must be a space after intersection type annotation separator// Options: ["never"]typeX=string&number;// Message: There must be no space before intersection type annotation separator// Options: ["never"]typeX=string&number;// Message: There must be no space after intersection type annotation separator

The following patterns are not considered problems:

typeX=string|number;typeX=string|number|boolean;typeX=(string)|number;typeX=((string))|(number|foo);// Options: ["never"]typeX=string|numbertypeX=|string|numberfunctionx(){typeX=|string|number}// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeX=string|number;typeX=string&number;typeX=string&number&boolean;typeX=(string)&number;typeX=((string))&(number&foo);// Options: ["never"]typeX=string&numbertypeX=&string&numberfunctionx(){typeX=&string&number}// Settings: {"flowtype":{"onlyFilesWithFlowAnnotation":true}}typeX=string&number;

use-flow-type

Marks Flowtype alias declarations as used.

Used to suppressno-unused-vars errors that are triggered by type aliases.

The following patterns are not considered problems:

declareclassA{}// Additional rules: {"no-unused-vars":1}declarefunctionA():Y// Additional rules: {"no-unused-vars":1}declaremoduleA{}// Additional rules: {"no-unused-vars":1}declaremoduleA{declarevara:Y}// Additional rules: {"no-unused-vars":1}declarevar A:Y// Additional rules: {"no-unused-vars":1}importtypeAfrom"a";typeX<B=ComponentType<A>>={b:B}; letx:X;console.log(x);// Additional rules: {"no-unused-vars":1}importtypeAfrom"a";typeX<B=A<string>>={b:B}; letx:X;console.log(x);// Additional rules: {"no-unused-vars":1}

use-read-only-spread

Warns against accidentally creating an object which is no longer read-only because of how spread operator works in Flow. Imagine the following code:

type INode = {|  +type: string,|};type Identifier = {|  ...INode,  +name: string,|};

You might expect the identifier name to be read-only, however, that's not true (flow.org/try):

const x: Identifier = { name: '', type: '' };x.type = 'must NOT be writable!'; // No Flow errorx.name = 'must NOT be writable!'; // No Flow error

This rule suggests to use$ReadOnly<…> to prevent accidental loss of readonly-ness:

type Identifier = $ReadOnly<{|  ...INode,  +name: string,|}>;const x: Identifier = { name: '', type: '' };x.type = 'must NOT be writable!'; // $FlowExpectedError[cannot-write]x.name = 'must NOT be writable!'; // $FlowExpectedError[cannot-write]

The following patterns are considered problems:

typeINode={||};typeIdentifier={|  ...INode,+aaa:string,|};// Message: Flow type with spread property and all readonly properties must be wrapped in '$ReadOnly<…>' to prevent accidental loss of readonly-ness.typeINode={||};typeIdentifier={|  ...INode,+aaa:string,+bbb:string,|};// Message: Flow type with spread property and all readonly properties must be wrapped in '$ReadOnly<…>' to prevent accidental loss of readonly-ness.

The following patterns are not considered problems:

typeINode={||};typeIdentifier={|  ...INode,name:string,|};typeINode={||};typeIdentifier={|  ...INode,name:string,// writable on purpose+surname:string,|};typeIdentifier={|+name:string,|};typeINode={||};typeIdentifier=$ReadOnly<{|  ...INode,+name:string,|}>;typeINode={||};typeIdentifier=$ReadOnly<{|  ...INode,name:string,// writable on purpose|}>;typeINode={||};typeIdentifier=$ReadOnly<{|  ...INode,-name:string,|}>;

valid-syntax

Deprecated Babylon (the Babel parser) v6.10.0 fixes parsing of the invalid syntax this plugin warned against.

Checks for simple Flow syntax errors.

The following patterns are not considered problems:

functionx(foo:string="1"){}functionx(foo:Type=bar()){}

About

Flow type linting rules for ESLint.

Topics

Resources

License

Contributing

Stars

Watchers

Forks

Sponsor this project

  •  

Packages

No packages published

Contributors70


[8]ページ先頭

©2009-2025 Movatter.jp