eslint-plugin-flowtype

raw JSON →
8.0.3 verified Sat Apr 25 auth: no javascript

ESLint plugin providing Flow type linting rules. Current stable version is 8.0.3, released October 2021. It adds over 40 rules specific to Flow type annotations, such as enforcing type styles, preventing duplicates, and requiring type declarations. Key differentiators: it is the primary ESLint plugin for Flow, with extensive rule coverage and shareable configs. It requires ESLint 8+ and Node 12+. Maintenance is active but may slow as Flow usage declines. Alternative: use TypeScript with `@typescript-eslint` instead.

error Error: Failed to load plugin 'flowtype' - Cannot find module 'eslint-plugin-flowtype'
cause Missing eslint-plugin-flowtype dependency
fix
npm install --save-dev eslint-plugin-flowtype
error Error: ESLint configuration in .eslintrc.json is invalid: "plugins" must be an array
cause Wrong format for plugins field
fix
Use 'plugins': ['flowtype']
error Error: Cannot find module '@babel/plugin-syntax-flow'
cause Missing peer dependency
fix
npm install --save-dev @babel/plugin-syntax-flow @babel/plugin-transform-react-jsx
breaking v8.0.0 drops support for ESLint v7 and Node v10.
fix Upgrade to ESLint 8+ and Node 12+.
breaking v6.0.0 contains potentially breaking dependency updates.
fix Review changelog for full list of updated dependencies.
deprecated v7.0.0 dropped Node v10 support.
fix Use Node >=12.
gotcha Adding 'eslint-plugin-flowtype' as plugin name will not work.
fix Use 'flowtype' without prefix.
gotcha Rules must be prefixed with 'flowtype/' in rule configuration.
fix Use 'flowtype/rule-name' instead of just 'rule-name'.
npm install eslint-plugin-flowtype
yarn add eslint-plugin-flowtype
pnpm add eslint-plugin-flowtype

Installation and basic ESLint configuration with recommended rules and a simple Flow-annotated function.

// Install: npm install --save-dev eslint eslint-plugin-flowtype @babel/plugin-syntax-flow @babel/plugin-transform-react-jsx

// .eslintrc.json
{
  "plugins": ["flowtype"],
  "extends": ["plugin:flowtype/recommended"],
  "rules": {
    "flowtype/boolean-style": [2, "boolean"],
    "flowtype/define-flow-type": 1,
    "flowtype/delimiter-dangle": [1, "never"],
    "flowtype/generic-spacing": [1, "never"],
    "flowtype/no-mixed": 2,
    "flowtype/no-primitive-constructor-types": 2,
    "flowtype/no-weak-types": 2,
    "flowtype/object-type-delimiter": [1, "comma"],
    "flowtype/require-parameter-type": 2,
    "flowtype/require-return-type": [2, "always", { "annotateUndefined": "never" }],
    "flowtype/require-valid-file-annotation": 2,
    "flowtype/semi": [1, "always"],
    "flowtype/space-after-type-colon": [1, "always"],
    "flowtype/space-before-generic-bracket": [1, "never"],
    "flowtype/space-before-type-colon": [1, "never"],
    "flowtype/type-id-match": [2, "^([A-Z][a-z0-9]+)+Type$"],
    "flowtype/union-intersection-spacing": [1, "always"],
    "flowtype/use-flow-type": 1,
    "flowtype/valid-syntax": 1
  }
}

// Example .js file with Flow
// @flow
function square(n: number): number {
  return n * n;
}