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

index.mddocs/

ESLint Plugin Flowtype

ESLint Plugin Flowtype provides comprehensive linting rules for Flow type annotations in JavaScript projects. It offers 49 specialized rules for validating Flow syntax, enforcing code style, and preventing common type-related errors. The plugin integrates seamlessly with ESLint configurations and provides shareable configurations for consistent Flow type checking across projects.

Package Information

  • Package Name: eslint-plugin-flowtype
  • Package Type: npm
  • Language: JavaScript
  • Installation: npm install eslint-plugin-flowtype

Core Imports

ESLint plugins are loaded through ESLint configuration rather than direct imports:

// .eslintrc.js
module.exports = {
  plugins: ['flowtype'],
  extends: ['plugin:flowtype/recommended'],
  rules: {
    // Individual rule configuration
    'flowtype/boolean-style': ['error', 'boolean'],
    'flowtype/define-flow-type': 'warn'
  }
};

For accessing plugin utilities programmatically:

const flowtypePlugin = require('eslint-plugin-flowtype');

Basic Usage

ESLint Configuration

// .eslintrc.js
module.exports = {
  parser: '@babel/eslint',
  parserOptions: {
    babelOptions: {
      plugins: [
        '@babel/plugin-transform-react-jsx',
        '@babel/plugin-syntax-flow'
      ]
    }
  },
  plugins: ['flowtype'],
  extends: ['plugin:flowtype/recommended'],
  settings: {
    flowtype: {
      onlyFilesWithFlowAnnotation: false
    }
  }
};

Flow File Example

// @flow
type User = {
  name: string,
  age: number,
  active: boolean
};

function processUser(user: User): string {
  return `${user.name} (${user.age})`;
}

Architecture

ESLint Plugin Flowtype is structured around several key components:

  • Rules Engine: 45 specialized ESLint rules for Flow type validation and formatting
  • Configuration System: Predefined configurations including recommended settings
  • Utility Functions: Helper functions for Flow file detection and rule processing
  • Flow Integration: Deep integration with Flow's AST and type system through Babel parser

Capabilities

Flow Type Validation Rules

Rules that validate Flow type syntax and prevent common type-related errors, including duplicate type detection, weak type prevention, and Flow-specific syntax validation.

// Plugin structure
const plugin = {
  configs: {
    recommended: ESLintConfig
  },
  rules: {
    [ruleName: string]: ESLintRule
  },
  rulesConfig: {
    [ruleName: string]: number
  }
};

interface ESLintConfig {
  parser: string;
  parserOptions: ParserOptions;
  plugins: string[];
  rules: { [ruleName: string]: RuleConfiguration };
  settings: { flowtype: FlowtypeSettings };
}

interface ESLintRule {
  create: (context: ESLintContext) => RuleImplementation;
  meta?: RuleMeta;
  schema?: JSONSchema;
}

Flow Type Validation Rules

Flow Type Formatting Rules

Rules that enforce consistent formatting and style for Flow type annotations, including spacing, delimiters, and code organization.

interface RuleConfiguration {
  0 | 1 | 2 | 'off' | 'warn' | 'error': RuleLevel;
  [options: any[]]: RuleOptions;
}

interface FlowtypeSettings {
  onlyFilesWithFlowAnnotation?: boolean;
}

Flow Type Formatting Rules

Flow Type Requirement Rules

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

interface ESLintContext {
  getFilename(): string;
  getSourceCode(): SourceCode;
  report(descriptor: ReportDescriptor): void;
  options: any[];
}

interface ReportDescriptor {
  node: ASTNode;
  message: string;
  fix?: (fixer: RuleFixer) => Fix;
}

Flow Type Requirement Rules

Plugin Configuration

Predefined ESLint configurations and settings for Flow type checking integration.

interface ParserOptions {
  babelOptions: {
    plugins: string[];
  };
}

const configs = {
  recommended: ESLintConfig
};

Plugin Configuration

Utility Functions

Helper functions for Flow file detection, AST processing, and rule implementation support.

function checkFlowFileAnnotation(ruleCreate: Function): Function;
function isFlowFile(context: ESLintContext): boolean;
function fuzzyStringMatch(needle: string, haystack: string): boolean;

Utility Functions

Types

interface ASTNode {
  type: string;
  range: [number, number];
  loc: SourceLocation;
}

interface SourceLocation {
  start: Position;
  end: Position;
}

interface Position {
  line: number;
  column: number;
}

interface RuleFixer {
  insertTextBefore(node: ASTNode, text: string): Fix;
  insertTextAfter(node: ASTNode, text: string): Fix;
  replaceText(node: ASTNode, text: string): Fix;
  removeRange(range: [number, number]): Fix;
}

interface Fix {
  range: [number, number];
  text: string;
}

interface RuleMeta {
  docs?: {
    description: string;
    category: string;
    recommended: boolean;
  };
  fixable?: 'code' | 'whitespace';
  schema?: JSONSchema;
}