README
This project was heavily based off the original flowtype eslint plugin, all credits go to the original maintainers. We duplicated the project with the intention of providing the flowtype community support and maintenance from people that actually used flowtype.
- Installation
- Configuration
- Settings
- Rules
array-style-complex-type
array-style-simple-type
arrow-parens
boolean-style
define-flow-type
delimiter-dangle
enforce-line-break
enforce-suppression-code
generic-spacing
interface-id-match
newline-after-flow-annotation
no-dupe-keys
no-duplicate-type-union-intersection-members
no-existential-type
no-flow-fix-me-comments
no-flow-suppressions-in-strict-files
no-internal-flow-type
no-mixed
no-mutable-array
no-primitive-constructor-types
no-types-missing-file-annotation
no-unused-expressions
no-weak-types
object-type-curly-spacing
object-type-delimiter
quotes
require-compound-type-alias
require-exact-type
require-indexer-name
require-inexact-type
require-parameter-type
require-readonly-react-props
require-return-type
require-types-at-top
require-valid-file-annotation
require-variable-type
semi
sort-keys
sort-type-union-intersection-members
space-after-type-colon
space-before-generic-bracket
space-before-type-colon
spread-exact-type
type-id-match
type-import-style
union-intersection-spacing
use-flow-type
use-read-only-spread
valid-syntax
Installation
npm install eslint-plugin-ft-flow eslint @babel/eslint-parser @babel/plugin-syntax-flow @babel/plugin-syntax-jsx --save-dev
# or with yarn
yarn add -D eslint-plugin-ft-flow eslint @babel/eslint-parser @babel/plugin-syntax-flow @babel/plugin-syntax-jsx
Configuration
- Set
parser
property to@babel/eslint-parser
. - Add
plugins
section and specifyeslint-plugin-ft-flow
as a plugin. - Enable rules.
{
"parser": "@babel/eslint-parser",
"plugins": [
"ft-flow"
],
"rules": {
"ft-flow/boolean-style": [
2,
"boolean"
],
// ... more rules
},
"settings": {
"ft-flow": {
"onlyFilesWithFlowAnnotation": false
}
}
}
Shareable configurations
Recommended
This plugin exports a recommended configuration that enforces Flowtype best practices.
To enable this configuration use the extends property in your .eslintrc
config file:
{
"extends": [
"plugin:ft-flow/recommended"
],
"plugins": [
"ft-flow"
]
}
See ESLint documentation for more information about extending configuration files.
Settings
onlyFilesWithFlowAnnotation
When true
, only checks files with a @flow
annotation in the first comment.
{
"settings": {
"ft-flow": {
"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 using Type[]
instead of Array<Type>
.
If it is 'shorthand'
then a problem is raised when using Array<Type>
instead of Type[]
.
The default value is 'verbose'
.
The following patterns are considered problems:
type X = (?string)[]
// Message: Use "Array<?string>", not "(?string)[]"
// Options: ["verbose"]
type X = (?string)[]
// Message: Use "Array<?string>", not "(?string)[]"
// Options: ["shorthand"]
type X = Array<?string>
// Message: Use "(?string)[]", not "Array<?string>"
// Options: ["shorthand"]
type X = Array<{foo: string}>
// Message: Use "{foo: string}[]", not "Array<{foo: string}>"
type X = (string | number)[]
// Message: Use "Array<string | number>", not "(string | number)[]"
type X = (string & number)[]
// Message: Use "Array<string & number>", not "(string & number)[]"
type X = [string, number][]
// Message: Use "Array<[string, number]>", not "[string, number][]"
type X = {foo: string}[]
// Message: Use "Array<{foo: string}>", not "{foo: string}[]"
type X = (string => number)[]
// Message: Use "Array<string => number>", not "(string => number)[]"
type X = {
foo: string,
bar: number
}[]
// Message: Use "Array<{ foo: string, bar: number }>", not "{ foo: string, bar: number }[]"
type X = {
foo: string,
bar: number,
quo: boolean,
hey: Date
}[]
// Message: Use "Array<Type>", not "Type[]"
The following patterns are not considered problems:
type X = Array<?string>
// Options: ["verbose"]
type X = Array<?string>
// Options: ["shorthand"]
type X = (?string)[]
// Options: ["shorthand"]
type X = Array<string>
// Options: ["shorthand"]
// Settings: {"ft-flow":{"onlyFilesWithFlowAnnotation":true}}
type X = 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:
- Primitive types
- Literal types
- Mixed type
- Any type
- Class type
- Generic type
- Array type shorthand notation
This rule takes one argument.
If it is 'verbose'
then a problem is raised when using Type[]
instead of Array<Type>
.
If it is 'shorthand'
then a problem is raised when using Array<Type>
instead of Type[]
.
The default value is 'verbose'
.
The following patterns are considered problems:
type X = string[]
// Message: Use "Array<string>", not "string[]"
// Options: ["verbose"]
type X = string[]
// Message: Use "Array<string>", not "string[]"
// Options: ["shorthand"]
type X = Array<string>
// Message: Use "string[]", not "Array<string>"
type X = Date[]
// Message: Use "Array<Date>", not "Date[]"
type X = Promise<string>[]
// Message: Use "Array<Promise<string>>", not "Promise<string>[]"
type X = $Keys<{foo: string}>[]
// Message: Use "Array<$Keys<{foo: string}>>", not "$Keys<{foo: string}>[]"
type X = any[]
// Message: Use "Array<any>", not "any[]"
type X = mixed[]
// Message: Use "Array<mixed>", not "mixed[]"
type X = void[]
// Message: Use "Array<void>", not "void[]"
type X = null[]
// Message: Use "Array<null>", not "null[]"
type X = Promise<{
foo: string,
bar: number
}>[]
// Message: Use "Array<Promise<{ foo: string, bar: number }>>", not "Promise<{ foo: string, bar: number }>[]"
type X = Promise<{
foo: string,
bar: number,
quo: boolean
}>[]
// Message: Use "Array<Type>", not "Type[]"
The following patterns are not considered problems:
type X = Array<string>
// Options: ["verbose"]
type X = Array<string>
// Options: ["shorthand"]
type X = string[]
type X = Array<Array<string>>
// Options: ["verbose"]
type X = (?string)[]
// Options: ["verbose"]
// Settings: {"ft-flow":{"onlyFilesWithFlowAnnotation":true}}
type X = string[]
type X = Array
type X = typeof Array
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: undefined
a => a
// Message: undefined
a => {
}
// Message: undefined
a.then(foo => {});
// Message: undefined
a.then(foo => a);
// Message: undefined
a(foo => { if (true) {}; });
// Message: undefined
a(async foo => { 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}]
async a => {}
// 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}]
async a => ({})
// Options: ["as-needed",{"requireForBlockBody":true}]
async a => 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) => { return a; }
// Options: ["always",{"requireForBlockBody":true}]
<T>(a: T) => { return a; }
// Options: ["as-needed",{"requireForBlockBody":true}]
<T>(a: T) => { return a; }
// Options: ["as-needed",{"requireForBlockBody":true}]
(a): %checks => typeof a === "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 using bool
instead of boolean
.
If it is 'bool'
then a problem is raised when using boolean
instead of bool
.
The default value is 'boolean'
.
The following patterns are considered problems:
type X = bool
// Message: Use "boolean", not "bool"
// Options: ["boolean"]
type X = bool
// Message: Use "boolean", not "bool"
// Options: ["bool"]
type X = boolean
// Message: Use "bool", not "boolean"
The following patterns are not considered problems:
type X = boolean
// Options: ["boolean"]
type X = boolean
// Options: ["bool"]
type X = bool
// Options: ["boolean"]
// Settings: {"ft-flow":{"onlyFilesWithFlowAnnotation":true}}
type X = bool
define-flow-type
Marks Flow type identifiers as defined.
Used to suppress no-undef
reporting of type identifiers.
The following patterns are not considered problems:
var a: AType
// Additional rules: {"no-undef":2}
var a: AType; var b: AType
// Additional rules: {"no-undef":2}
var a; (a: AType)
// Additional rules: {"no-undef":2}
var a: 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: {"ft-flow":{"onlyFilesWithFlowAnnotation":true}}
/**
* Copyright 2019 no corp
* @flow
*/
type Foo = $ReadOnly<{}>
// Additional rules: {"no-undef":2}
enum Status { Active, Paused }
// Additional rules: {"no-undef":2}
enum Status { Active = 'active', Paused = 'paused' }
// Additional rules: {"no-undef":2}
enum Status { Active = 1, Paused = 2 }
// Additional rules: {"no-undef":2}
var a: AType
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}
var a: AType; var b: AType
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}
var a; (a: AType)
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}
var a: 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: {"ft-flow":{"onlyFilesWithFlowAnnotation":true}}
/**
* Copyright 2019 no corp
* @flow
*/
type Foo = $ReadOnly<{}>
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}
enum Status { Active, Paused }
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}
enum Status { Active = 'active', Paused = 'paused' }
// Additional rules: {"no-undef":2,"no-use-before-define":[2,"nofunc"]}
enum Status { Active = 1, Paused = 2 }
// 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 default comma-dangle
rule:
- The first argument is for Object and Tuple annotations. The default value is
'never'
. - The second argument is used for Interface annotations. This defaults to the value of the first argument.
- 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 there is a trailing comma on a single-line definition.
If it is 'only-multiline'
then a problem is raised when there is a trailing comma on a single-line definition. It allows, but does not enforce, trailing commas on multi-line definitions.
The following patterns are considered problems:
type X = { foo: string, }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = { foo: string, }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = { foo: string; }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = {
foo: string,
}
// Message: Unexpected trailing delimiter
// Options: ["always"]
type X = { foo: string }
// Message: Missing trailing delimiter
// Options: ["always"]
type X = {
foo: string
}
// Message: Missing trailing delimiter
// Options: ["always-multiline"]
type X = { foo: string, }
// Message: Unexpected trailing delimiter
// Options: ["always-multiline"]
type X = {
foo: string
}
// Message: Missing trailing delimiter
// Options: ["only-multiline"]
type X = { foo: string; }
// Message: Unexpected trailing delimiter
// Options: ["always","never"]
interface X { foo: string; }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = { [key: string]: number, }
// Message: Unexpected trailing delimiter
// Options: ["always"]
type X = { [key: string]: number }
// Message: Missing trailing delimiter
// Options: ["always-multiline"]
type X = { [key: string]: number, }
// Message: Unexpected trailing delimiter
// Options: ["always-multiline"]
type X = {
[key: string]: number
}
// Message: Missing trailing delimiter
// Options: ["only-multiline"]
type X = { [key: string]: number; }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = { [key: string]: number, foo: string, }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = {
[key: string]: number,
foo: string,
}
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = {
[key: string]: number,
aReallyLongPropertyNameHere: string,
}
// Message: Unexpected trailing delimiter
// Options: ["always"]
type X = { [key: string]: number, foo: string }
// Message: Missing trailing delimiter
// Options: ["always"]
type X = {
[key: string]: number;
foo: string
}
// Message: Missing trailing delimiter
// Options: ["always-multiline"]
type X = { [key: string]: number, foo: string, }
// Message: Unexpected trailing delimiter
// Options: ["always-multiline"]
type X = {
[key: string]: number,
foo: string
}
// Message: Missing trailing delimiter
// Options: ["only-multiline"]
type X = { [key: string]: number, foo: string, }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = { foo: string, [key: string]: number, }
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = {
foo: string,
[key: string]: number,
}
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = {
aReallyLongPropertyNameHere: string,
[key: string]: number,
}
// Message: Unexpected trailing delimiter
// Options: ["always"]
type X = { foo: string, [key: string]: number }
// Message: Missing trailing delimiter
// Options: ["always"]
type X = { foo: string; [key: string]: number }
// Message: Missing trailing delimiter
// Options: ["always-multiline"]
type X = { foo: string, [key: string]: number; }
// Message: Unexpected trailing delimiter
// Options: ["always-multiline"]
type X = {
foo: string,
[key: string]: number
}
// Message: Missing trailing delimiter
// Options: ["only-multiline"]
type X = { foo: string, [key: string]: number; }
// Message: Unexpected trailing delimiter
type X = { ..., }
// Message: Unexpected trailing delimiter
type X = { ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = { ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = { ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","always"]
type X = { ... }
// Message: Missing trailing delimiter
// Options: ["never","never","always-multiline"]
type X = { ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","always-multiline"]
type X = { ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","only-multiline"]
type X = { ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","only-multiline"]
type X = { ...; }
// Message: Unexpected trailing delimiter
type X = {
...,
}
// Message: Unexpected trailing delimiter
type X = {
...;
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = {
...,
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = {
...;
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","always"]
type X = {
...
}
// Message: Missing trailing delimiter
// Options: ["never","never","always-multiline"]
type X = {
...
}
// Message: Missing trailing delimiter
type X = { foo: string, ..., }
// Message: Unexpected trailing delimiter
type X = { foo: string; ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = { foo: string, ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = { foo: string; ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","always"]
type X = { foo: string, ... }
// Message: Missing trailing delimiter
// Options: ["never","never","always-multiline"]
type X = { foo: string, ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","always-multiline"]
type X = { foo: string; ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","only-multiline"]
type X = { foo: string, ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","only-multiline"]
type X = { foo: string; ...; }
// Message: Unexpected trailing delimiter
type X = {
foo: string,
...,
}
// Message: Unexpected trailing delimiter
type X = {
foo: string;
...;
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = {
foo: string,
...,
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = {
foo: string;
...;
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","always"]
type X = {
foo: string,
...
}
// Message: Missing trailing delimiter
// Options: ["never","never","always-multiline"]
type X = {
foo: string,
...
}
// Message: Missing trailing delimiter
type X = { [key: string]: number, ..., }
// Message: Unexpected trailing delimiter
type X = { [key: string]: number; ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = { [key: string]: number, ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = { [key: string]: number; ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","always"]
type X = { [key: string]: number, ... }
// Message: Missing trailing delimiter
// Options: ["never","never","always-multiline"]
type X = { [key: string]: number, ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","always-multiline"]
type X = { [key: string]: number; ...; }
// Message: Unexpected trailing delimiter
// Options: ["never","never","only-multiline"]
type X = { [key: string]: number, ..., }
// Message: Unexpected trailing delimiter
// Options: ["never","never","only-multiline"]
type X = { [key: string]: number; ...; }
// Message: Unexpected trailing delimiter
type X = {
[key: string]: number,
...,
}
// Message: Unexpected trailing delimiter
type X = {
[key: string]: number;
...;
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = {
[key: string]: number,
...,
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","never"]
type X = {
[key: string]: number;
...;
}
// Message: Unexpected trailing delimiter
// Options: ["never","never","always"]
type X = {
[key: string]: number,
...
}
// Message: Missing trailing delimiter
// Options: ["never","never","always-multiline"]
type X = {
[key: string]: number,
...
}
// Message: Missing trailing delimiter
type X = [string, number,]
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = [string, number,]
// Message: Unexpected trailing delimiter
// Options: ["never"]
type X = [
string,
number,
]
// Message: Unexpected trailing delimiter
// Options: ["always"]
type X = [string, number]
// Message: Missing trailing delimiter
// Options: ["always"]
type X = [
string,
number
]
// Message: Missing trailing delimiter
// Options: ["always-multiline"]
type X = [string, number,]
// Message: Unexpected trailing delimiter
// Options: ["always-multiline"]
type X = [
foo, string
]
// Message: Missing trailing delimiter
// Options: ["only-multiline"]
type X = [ number, string, ]
// Message: Unexpected trailing delimiter
The following patterns are not considered problems:
type X = { foo: string }
// Options: ["never"]
type X = { foo: string }
// Options: ["always"]
type X = { foo: string, }
// Options: ["always"]
type X = { foo: string; }
// Options: ["never"]
type X = {
foo: string
}
// Options: ["always"]
type X = {
foo: string,
}
// Options: ["always-multiline"]
type X = { foo: string }
// Options: ["always-multiline"]
type X = {
foo: string,
}
// Options: ["always-multiline"]
type X = {
foo: string;
}
// Options: ["only-multiline"]
type X = { foo: string }
// Options: ["only-multiline"]
type X = {
foo: string
}
// Options: ["only-multiline"]
type X = {
foo: string,
}
// Options: ["only-multiline"]
type X = {
foo: string;
}
// Options: ["never","always"]
interface X { foo: string; }
// Options: ["never"]
type X = {}
// Options: ["always"]
type X = {}
// Options: ["always-multiline"]
type X = {}
// Options: ["only-multiline"]
type X = {}
// Options: ["never"]
type X = { [key: string]: number }
// Options: ["always"]
type X = { [key: string]: number, }
// Options: ["always"]
type X = { [key: string]: number; }
// Options: ["always-multiline"]
type X = { [key: string]: number }
// Options: ["always-multiline"]
type X = {
[key: string]: number,
}
// Options: ["only-multiline"]
type X = {
[key: string]: number,
}
// Options: ["only-multiline"]
type X = {
[key: string]: number
}
// Options: ["only-multiline"]
type X = { [key: string]: number }
// Options: ["never"]
type X = { [key: string]: number, foo: string }
// Options: ["always"]
type X = { [key: string]: number, foo: string, }
// Options: ["always"]
type X = { [key: string]: number; foo: string; }
// Options: ["always-multiline"]
type X = { [key: string]: number, foo: string }
// Options: ["always-multiline"]
type X = {
[key: string]: number,
foo: string,
}
// Options: ["only-multiline"]
type X = {
[key: string]: number,
foo: string,
}
// Options: ["only-multiline"]
type X = {
[key: string]: number;
foo: string
}
// Options: ["only-multiline"]
type X = { [key: string]: number, foo: string }
// Options: ["never"]
type X = { foo: string, [key: string]: number }
// Options: ["always"]
type X = { foo: string, [key: string]: number, }
// Options: ["always"]
type X = { foo: string; [key: string]: number; }
// Options: ["always-multiline"]
type X = { foo: string, [key: string]: number }
// Options: ["always-multiline"]
type X = {
foo: string,
[key: string]: number,
}
// Options: ["only-multiline"]
type X = {
foo: string,
[key: string]: number,
}
// Options: ["only-multiline"]
type X = {
foo: string;
[key: string]: number
}
// Options: ["only-multiline"]
type X = { foo: string, [key: string]: number }
type X = { ... }
// Options: ["never","never","never"]
type X = { ... }
// Options: ["never","never","always"]
type X = { ..., }
// Options: ["never","never","always-multiline"]
type X = { ... }
// Options: ["never","never","only-multiline"]
type X = { ... }
type X = {
...
}
// Options: ["never","never","never"]
type X = {
...
}
// Options: ["never","never","always"]
type X = {
...,
}
// Options: ["never","never","always"]
type X = {
...;
}
// Options: ["never","never","always-multiline"]
type X = {
...,
}
// Options: ["never","never","always-multiline"]
type X = {
...;
}
// Options: ["never","never","only-multiline"]
type X = {
...
}
// Options: ["never","never","only-multiline"]
type X = {
...,
}
// Options: ["never","never","only-multiline"]
type X = {
...;
}
type X = { foo: string, ... }
// Options: ["never","never","never"]
type X = { foo: string, ... }
// Options: ["never","never","always"]
type X = { foo: string, ..., }
// Options: ["never","never","always"]
type X = { foo: string; ...; }
// Options: ["never","never","always-multiline"]
type X = { foo: string, ... }
// Options: ["never","never","only-multiline"]
type X = { foo: string, ... }
type X = {
foo: string,
...
}
// Options: ["never","never","never"]
type X = {
foo: string,
...
}
// Options: ["never","never","always"]
type X = {
foo: string,
...,
}
// Options: ["never","never","always"]
type X = {
foo: string;
...;
}
// Options: ["never","never","always-multiline"]
type X = {
foo: string,
...,
}
// Options: ["never","never","always-multiline"]
type X = {
foo: string;
...;
}
// Options: ["never","never","only-multiline"]
type X = {
foo: string,
...
}
// Options: ["never","never","only-multiline"]
type X = {
foo: string,
...,
}
// Options: ["never","never","only-multiline"]
type X = {
foo: string,
...;
}
// Options: ["never","never","never"]
type X = { [key: string]: number, ... }
// Options: ["never","never","always"]
type X = { [key: string]: number, ..., }
// Options: ["never","never","always"]
type X = { [key: string]: number; ...; }
// Options: ["never","never","always-multiline"]
type X = { [key: string]: number, ... }
// Options: ["never","never","only-multiline"]
type X = { [key: string]: number, ... }
// Options: ["never","never","never"]
type X = {
[key: string]: number,
...
}
// Options: ["never","never","always"]
type X = {
[key: string]: number,
...,
}
// Options: ["never","never","always"]
type X = {
[key: string]: number;
...;
}
// Options: ["never","never","always-multiline"]
type X = {
[key: string]: number,
...,
}
// Options: ["never","never","always-multiline"]
type X = {
[key: string]: number;
...;
}
// Options: ["never","never","only-multiline"]
type X = {
[key: string]: number,
...
}
// Options: ["never","never","only-multiline"]
type X = {
[key: string]: number,
...,
}
// Options: ["never","never","only-multiline"]
type X = {
[key: string]: number;
...;
}
type X = [string, number]
// Options: ["never"]
type X = [string, number]
// Options: ["never"]
type X = [
string,
number
]
// Options: ["always"]
type X = [string, number,]
// Options: ["always"]
type X = [
string,
number,
]
// Options: ["always-multiline"]
type X = [ foo, string ]
// Options: ["always-multiline"]
type X = [
foo, string,
]
// Options: ["only-multiline"]
type X = [ number, string ]
// Options: ["only-multiline"]
type X = [
number,
string
]
// Options: ["only-multiline"]
type X = [
number,
string,
]
// Options: ["never"]
type X = []
// Options: ["always"]
type X = []
// Options: ["always-multiline"]
type X = []
// Options: ["only-multiline"]
type X = []
enforce-line-break
This rule enforces line breaks between type definitions.
The following patterns are considered problems:
type baz = 6;
const hi = 2;
// Message: New line required below type declaration
const foo = 6;
type hi = 2;
// Message: New line required above type declaration
const som = "jes";
// a comment
type fed = "hed";
// Message: New line required above type declaration
type som = "jes";
// a comment
const fed = "hed";
// Message: New line required below type declaration
type hello = 34;
const som = "jes";
type fed = "hed";
// Message: New line required below type declaration
// Message: New line required above type declaration
const a = 5;
export type hello = 34;
// Message: New line required above type declaration
const a = 5;
// a comment
export type hello = 34;
// Message: New line required above type declaration
const a = 5;
/**
* a jsdoc block
*/
type hello = 34;
// Message: New line required above type declaration
The following patterns are not considered problems:
type gjs = 6;
type gjs = 6;
type hi = 2;
type X = 4;
const red = "serpent";
console.log("hello");
// number or string
type Y = string | number;
// resting + sleep
type snooze = "dreaming" | "";
type Props = {
accountBalance: string | number,
accountNumber: string | number,
};
const x = 4;
const y = 489;
// Some Comment
type Props = {
accountBalance: string | number,
accountNumber: string | number,
};
type RoadT = "grass" | "gravel" | "cement";
// @flow
type A = string
enforce-suppression-code
This rule enforces a suppression code on flow suppression comments such as $FlowFixMe
and $FlowExpectedError
.
The following patterns are considered problems:
// $FlowFixMe I am doing something evil here
const text = 'HELLO';
// Message: $FlowFixMe is missing a suppression error code. Please update this suppression to use an error code: $FlowFixMe[…]
// $FlowExpectedError I am doing something evil here
const text = 'HELLO';
// Message: $FlowExpectedError is missing a suppression error code. Please update this suppression to use an error code: $FlowExpectedError[…]
// $FlowIssue I am doing something evil here
const text = 'HELLO';
// Message: $FlowIssue is missing a suppression error code. Please update this suppression to use an error code: $FlowIssue[…]
// $FlowIgnore I am doing something evil here
const text = 'HELLO';
// Message: $FlowIgnore is missing a suppression error code. Please update this suppression to use an error code: $FlowIgnore[…]
/* $FlowIgnore I am doing something evil here */
// Message: $FlowIgnore is missing a suppression error code. Please update this suppression to use an error code: $FlowIgnore[…]
{ /* $FlowIgnore I am doing something evil here */ }
// Message: $FlowIgnore is missing a suppression error code. Please update this suppression to use an error code: $FlowIgnore[…]
/**
* $FlowIgnore I am doing something evil here
*/
// Message: $FlowIgnore is missing a suppression error code. Please update this suppression to use an error code: $FlowIgnore[…]
The following patterns are not considered problems:
// Just a random comment
//
const text = 'HELLO';
// $FlowFixMe[incompatible-call] TODO 48
const text = 'HELLO';
// $FlowExpectedError[incompatible-call] TODO 48
const text = 'HELLO';
// $FlowIssue[incompatible-call] TODO 48
const text = 'HELLO';
// $FlowIgnore[incompatible-call] TODO 48
const text = 'HELLO';
/* $FlowIgnore[incompatible-call] TODO 48 */
/**
* $FlowIgnore[incompatible-call] TODO 48
*/
/* $FlowIgnore[incompatible-call] TODO 48 */
generic-spacing
The --fix
option on the command line automatically fixes problems reported by this rule.
Enforces consistent spacing within generic type annotation parameters.
This rule takes one argument. If it is 'never'
then a problem is raised when there is a space surrounding the generic type parameters. If it is 'always'
then a problem is raised when there is no space surrounding the generic type parameters.
The default value is 'never'
.
The following patterns are considered problems:
type X = Promise< string>
// Message: There must be no space at start of "Promise" generic type annotation
// Options: ["never"]
type X = Promise< string>
// Message: There must be no space at start of "Promise" generic type annotation
type X = FooBar<string >
// Message: There must be no space at end of "FooBar" generic type annotation
type X = 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 annotation
type X = 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"]
type X = Promise<string >
// Message: There must be a space at start of "Promise" generic type annotation
// Options: ["always"]
type X = FooBar< string>
// Message: There must be a space at end of "FooBar" generic type annotation
// Options: ["always"]
type X = 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"]
type X = 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"]
type X = FooBar< string >
// Message: There must be one space at start of "FooBar" generic type annotation
// Options: ["always"]
type X = FooBar< string >
// Message: There must be one space at end of "FooBar" generic type annotation
// Options: ["always"]
type X = 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:
type X = Promise<string>
type X = Promise<(string)>
type X = Promise<(foo), bar, (((baz)))>
type X = Promise<
(foo),
bar,
(((baz)))
>
type X = Promise<
(foo),
bar,
(((baz)))
>
// Options: ["always"]
type X = Promise< string >
// Options: ["always"]
type X = Promise< (string) >
// Options: ["always"]
type X = Promise< (foo), bar, (((baz))) >
interface-id-match
Enforces a consistent naming pattern for interfaces.
Options
This rule requires a text RegExp:
{
"rules": {
"ft-flow/interface-id-match": [
2,
"^([A-Z][a-z0-9]*)+Type