Rules that validate Flow type syntax, prevent common type-related errors, and enforce Flow-specific best practices.
Enforces consistent array type annotation style for both simple and complex types.
// Rules: array-style-simple-type, array-style-complex-type
const rules = {
'array-style-simple-type': ESLintRule,
'array-style-complex-type': ESLintRule
};
// Configuration options
type ArrayStyleOption = 'verbose' | 'shorthand';Usage Examples:
// array-style-simple-type with 'shorthand' option
// ✓ Good
type Numbers = number[];
// ✗ Bad
type Numbers = Array<number>;
// array-style-complex-type with 'verbose' option
// ✓ Good
type ComplexArray = Array<{id: number, name: string}>;
// ✗ Bad
type ComplexArray = {id: number, name: string}[];Prevents duplicate keys in object types and duplicate members in union/intersection types.
const rules = {
'no-dupe-keys': ESLintRule,
'no-duplicate-type-union-intersection-members': ESLintRule
};Usage Examples:
// no-dupe-keys
// ✗ Bad
type User = {
name: string,
name: string // Duplicate key
};
// no-duplicate-type-union-intersection-members
// ✗ Bad
type StringOrNumber = string | number | string; // Duplicate 'string'Validates proper Flow syntax and prevents usage of deprecated or problematic Flow features.
const rules = {
'no-existential-type': ESLintRule,
'no-internal-flow-type': ESLintRule,
'valid-syntax': ESLintRule
};Usage Examples:
// no-existential-type
// ✗ Bad - Existential type operator is deprecated
type Exists = *;
// no-internal-flow-type
// ✗ Bad - Internal Flow types should not be used
type Internal = $FlowFixMe;Prevents usage of weak or problematic types that reduce type safety.
const rules = {
'no-weak-types': ESLintRule,
'no-mixed': ESLintRule,
'no-primitive-constructor-types': ESLintRule
};
// Configuration for no-weak-types
interface NoWeakTypesOptions {
any?: boolean;
Object?: boolean;
Function?: boolean;
}Usage Examples:
// no-weak-types
// ✗ Bad
function process(data: any): Object {
return new Function();
}
// no-mixed
// ✗ Bad
type MixedType = mixed;
// no-primitive-constructor-types
// ✗ Bad
type StringType = String; // Use 'string' insteadEnsures proper Flow file annotations and prevents missing annotations where required.
const rules = {
'no-types-missing-file-annotation': ESLintRule,
'require-valid-file-annotation': ESLintRule
};
// Configuration for require-valid-file-annotation
interface FileAnnotationOptions {
annotationStyle?: 'none' | 'line' | 'block';
strict?: boolean;
}Usage Examples:
// no-types-missing-file-annotation
// ✗ Bad - File has Flow types but no @flow annotation
type User = {name: string}; // Missing // @flow at top
// require-valid-file-annotation with 'line' option
// ✓ Good
// @flow
type User = {name: string};
// ✗ Bad with 'block' option
/* @flow */ // Should be line comment with 'line' optionValidates Flow-specific expressions and usage patterns.
const rules = {
'no-unused-expressions': ESLintRule,
'no-flow-fix-me-comments': ESLintRule
};Usage Examples:
// no-flow-fix-me-comments
// ✗ Bad
// $FlowFixMe - this needs proper typing
function broken(): any {
return null;
}
// no-unused-expressions
// ✗ Bad
type UnusedType = string; // Type is defined but never usedPrevents usage of mutable array types in favor of readonly arrays.
const rules = {
'no-mutable-array': ESLintRule
};Usage Examples:
// no-mutable-array
// ✗ Bad
type MutableList = Array<string>;
// ✓ Good
type ReadonlyList = $ReadOnlyArray<string>;Validates naming patterns for interfaces and type aliases.
const rules = {
'interface-id-match': ESLintRule,
'type-id-match': ESLintRule
};
// Configuration options
interface IdMatchOptions {
pattern: string;
flags?: string;
}Usage Examples:
// interface-id-match with pattern '^I[A-Z]'
// ✓ Good
interface IUser {
name: string;
}
// ✗ Bad
interface user { // Should start with 'I' and be PascalCase
name: string;
}
// type-id-match with pattern '^[A-Z]'
// ✓ Good
type UserType = {name: string};
// ✗ Bad
type userType = {name: string}; // Should be PascalCaseinterface ESLintRule {
create: (context: ESLintContext) => RuleListener;
meta?: {
docs?: RuleDocsType;
fixable?: 'code' | 'whitespace';
schema?: JSONSchema;
};
}
interface RuleListener {
[nodeType: string]: (node: ASTNode) => void;
}
interface RuleDocsType {
description: string;
category: string;
recommended?: boolean;
url?: string;
}