or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

docs

configuration.mdformatting-rules.mdindex.mdrequirement-rules.mdutilities.mdvalidation-rules.md
tile.json

requirement-rules.mddocs/

Flow Type Requirement Rules

Rules that enforce the presence of type annotations where required, including parameter types, return types, and variable types.

Capabilities

Function Type Requirements

Rules that require type annotations for function parameters and return values.

const rules = {
  'require-parameter-type': ESLintRule,
  'require-return-type': ESLintRule
};

// Configuration options
interface ParameterTypeOptions {
  excludeArrowFunctions?: boolean | 'expressionsOnly';
  excludeParameterMatch?: string;
}

interface ReturnTypeOptions {
  annotateUndefined?: 'always' | 'never' | 'always-in-exact';
  excludeArrowFunctions?: boolean | 'expressionsOnly';
  excludeMatching?: string[];
  includeOnlyMatching?: string[];
}

Usage Examples:

// require-parameter-type
// ✓ Good
function processUser(user: User, options: Options): void {}
const processData = (data: DataType) => data;

// ✗ Bad - missing parameter types
function processUser(user, options) {}
const processData = (data) => data;

// require-return-type
// ✓ Good  
function getName(user: User): string {
  return user.name;
}

function getUser(): User | null {
  return null;
}

// ✗ Bad - missing return types
function getName(user: User) {
  return user.name;
}

Variable Type Requirements

Rules that require type annotations for variable declarations.

const rules = {
  'require-variable-type': ESLintRule
};

// Configuration options
interface VariableTypeOptions {
  excludeVariableTypes?: {
    var?: boolean;
    let?: boolean;
    const?: boolean;
  };
  excludeVariableMatch?: string;
}

Usage Examples:

// require-variable-type
// ✓ Good
const userName: string = 'John';
let userAge: number = 25;
var isActive: boolean = true;

// ✗ Bad - missing variable types
const userName = 'John';
let userAge = 25;
var isActive = true;

React Props Requirements

Rules for requiring readonly React props and proper React component typing.

const rules = {
  'require-readonly-react-props': ESLintRule
};

Usage Examples:

// require-readonly-react-props
// ✓ Good
type Props = $ReadOnly<{
  name: string,
  age: number,
}>;

// ✗ Bad - props should be readonly
type Props = {
  name: string,
  age: number,
};

Object Type Requirements

Rules that require specific object type patterns and exact types.

const rules = {
  'require-exact-type': ESLintRule,
  'require-inexact-type': ESLintRule,
  'require-indexer-name': ESLintRule
};

Usage Examples:

// require-exact-type  
// ✓ Good - exact object type
type User = {|
  name: string,
  age: number,
|};

// ✗ Bad - inexact object type
type User = {
  name: string,
  age: number,
};

// require-inexact-type (opposite of require-exact-type)
// ✓ Good - inexact object type allows additional properties
type User = {
  name: string,
  age: number,
  ...
};

// require-indexer-name
// ✓ Good - indexer has a name
type StringMap = {
  [key: string]: string,
};

// ✗ Bad - indexer missing name  
type StringMap = {
  [string]: string,
};

Compound Type Requirements

Rules that require type aliases for complex compound types.

const rules = {
  'require-compound-type-alias': ESLintRule
};

// Configuration options
interface CompoundTypeOptions {
  allowIntersection?: boolean;
  allowUnion?: boolean;
  allowTuple?: boolean;
}

Usage Examples:

// require-compound-type-alias
// ✓ Good - complex type has alias
type UserOrProduct = User | Product;
type UserAndPermissions = User & Permissions;

function process(item: UserOrProduct): void {}

// ✗ Bad - complex type used inline
function process(item: User | Product): void {}
function combine(item: User & Permissions): void {}

Code Organization Requirements

Rules that require specific organization patterns for type definitions.

const rules = {
  'require-types-at-top': ESLintRule
};

// Configuration options
interface TypesAtTopOptions {
  checkImports?: boolean;
}

Usage Examples:

// require-types-at-top
// ✓ Good - types defined at top
// @flow

type User = {name: string};
type Product = {id: number};

function processUser(user: User): void {}
function processProduct(product: Product): void {}

// ✗ Bad - types mixed with implementation
function processUser(user: User): void {}

type User = {name: string};  // Should be at top

function processProduct(product: Product): void {}

Spread Type Requirements

Rules for requiring exact types when using object spread operations.

const rules = {
  'spread-exact-type': ESLintRule,
  'use-read-only-spread': ESLintRule
};

Usage Examples:

// spread-exact-type
// ✓ Good - exact type with spread
type User = {|
  name: string,
  age: number,
|};

const updatedUser = {...user, age: 26};

// ✗ Bad - inexact type with spread can cause issues
type User = {
  name: string,
  age: number,
};

// use-read-only-spread
// ✓ Good - readonly array spread
type ReadOnlyNumbers = $ReadOnlyArray<number>;
const combined = [...numbers];

// ✗ Bad - mutable array spread
type Numbers = Array<number>;
const combined = [...numbers];  // Should use readonly arrays

Advanced Configuration

Function Matching Patterns

Many requirement rules support pattern matching for excluding or including specific functions.

interface PatternOptions {
  excludeMatching?: string[];
  includeOnlyMatching?: string[];
  excludeArrowFunctions?: boolean | 'expressionsOnly';
}

Usage Examples:

// Configuration example
{
  "flowtype/require-return-type": [
    "error",
    {
      "excludeMatching": ["^test", "^mock"],
      "excludeArrowFunctions": "expressionsOnly"
    }
  ]
}

// With this config:
// ✓ Good - test functions excluded
function testSomething() {
  return true;
}

// ✓ Good - arrow expression excluded
const simple = x => x * 2;

// ✗ Bad - arrow statement requires return type
const complex = (x) => {
  return x * 2;
};  // Should be: const complex = (x): number => { return x * 2; };

Types

interface RequirementRule extends ESLintRule {
  create: (context: ESLintContext) => RuleListener;
  schema: JSONSchema[];
}

interface RuleListener {
  FunctionDeclaration?: (node: FunctionNode) => void;
  ArrowFunctionExpression?: (node: ArrowFunctionNode) => void;
  VariableDeclarator?: (node: VariableNode) => void;
  TypeAlias?: (node: TypeAliasNode) => void;
}

interface FunctionNode extends ASTNode {
  id: Identifier | null;
  params: Parameter[];
  returnType: TypeAnnotation | null;
  async: boolean;
  generator: boolean;
}

interface Parameter {
  name: string;
  typeAnnotation: TypeAnnotation | null;
  optional: boolean;
}

interface TypeAnnotation {
  type: string;
  typeAnnotation: FlowType;
}