enforces a particular style for boolean type annotations. This rule takes one argument.
✅ Enabled (error)
// GOOD
type AeType = boolean;
// BAD
/*
type BeType = bool;
type CeType = Boolean;
*/
marks Flow type identifiers as defined. Used to suppress
no-undef
reporting of type identifiers.
✅ Enabled (error)
// BAD
/*
const a: AeType = '';
*/
// GOOD
type BeType = string;
const b: BeType = '';
enforces consistent use of trailing commas in Object and Tuple annotations.
✅ Enabled (error)
// BAD
/*
type AeType = {
foo: string
};
*/
// GOOD
type BeType = {
foo: string,
};
enforces consistent spacing within generic type annotation parameters.
✅ Enabled (error)
// BAD
/*
type AeType = Promise< string>;
*/
// GOOD
type BeType = Promise<string>;
disallows use of primitive constructors as types, such as
Boolean
,Number
andString
. See more.
✅ Enabled (error)
// BAD
/*
type NumberType = Number;
type StringType = String;
type BooleanType = Boolean;
*/
// GOOD
type NumberType = number;
type StringType = string;
type BooleanType = boolean;
Warns against weak type annotations any, Object and Function. These types can cause flow to silently skip over portions of your code, which would have otherwise caused type errors.
❌ Disabled
// BAD
function foo(thing: string): any { return true; }
// GOOD
function foo(thing: string): boolean { return true; }
enforces consistent separators between properties in Flow object types.
✅ Enabled (error)
// BAD
/*
type FooType = { a: string; b: string };
type Foo2Type = {
a: string,
b: string
};
*/
// GOOD
type FooType = { a: string, b: string };
type Foo2Type = {
a: string,
b: string,
};
Overwrite require-jsdoc rule
❌ Disabled
// jsdoc is not required if you are using flow
function foo(thing: string): any { return true; }
requires that all function parameters have type annotations.
✅ Enabled (error)
// BAD
/*
function x(foo) {}
*/
// GOOD
function x(foo: string) {}
requires that functions have return type annotation.
✅ Enabled (error)
// BAD
/*
const a = (foo: string) => { return 'foo'; };
*/
// GOOD
const b = (foo: string): string => { return 'foo'; };
this rule validates Flow file annotations.
✅ Enabled (error)
// @flow
// or
/* @flow */
enforces consistent use of semicolons after type aliases.
✅ Enabled (error)
// BAD
/*
type FooType = {}
*/
// GOOD
type FooType = {};
enforces consistent spacing after the type annotation colon.
✅ Enabled (error)
// BAD
/*
const a = (foo:string) => {};
const b = (foo :string) => {};
const c = (foo : string) => {};
*/
// GOOD
const d = (foo: string) => {};
Enforces consistent spacing before the opening < of generic type annotation parameters.
✅ Enabled (error)
// BAD
/*
type XeType = Promise <string>;
*/
// GOOD
type XeType = Promise<string>;
Enforces consistent spacing before the type annotation colon.
✅ Enabled (error)
// BAD
/*
const a = (foo : string) => {};
*/
// GOOD
const b = (foo: string) => {};
Enforces a consistent naming pattern for type aliases.
✅ Enabled (error)
// BAD
/*
type foo = {};
*/
// GOOD
type FooType = {};
Enforces consistent spacing around union and intersection type separators (| and &).
✅ Enabled (error)
// BAD
/*
type XeType = string| number;
*/
// GOOD
type XeType = string | number;
Marks Flow type alias declarations as used. Used to suppress no-unused-vars errors that are triggered by type aliases.
✅ Enabled (error)
// GOOD
declare class A {}