You're Invited:Meet the Socket Team at BlackHat and DEF CON in Las Vegas, Aug 7-8.RSVP
Socket
Socket
Sign inDemoInstall

eslint-plugin-flowtype

Package Overview
Dependencies
Maintainers
1
Versions
185
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-flowtype

Flowtype linting rules for ESLint.


Version published
Weekly downloads
4.6M
decreased by-0.7%
Maintainers
1
Created
Weekly downloads
 

Package description

What is eslint-plugin-flowtype?

eslint-plugin-flowtype is an ESLint plugin that provides linting rules for Flow type annotations. It helps ensure that your Flow type annotations are correct and consistent, improving the reliability and maintainability of your code.

What are eslint-plugin-flowtype's main functionalities?

Type Annotations

This rule ensures that every file has a valid Flow file annotation. The code sample demonstrates a simple function with Flow type annotations for the parameters and return type.

/* eslint flowtype/require-valid-file-annotation: [2, "always"] */
// @flow
function add(a: number, b: number): number {
  return a + b;
}

Type Definitions

This rule ensures that all Flow type definitions are defined correctly. The code sample shows a type definition for a User object and an instance of that type.

/* eslint flowtype/define-flow-type: 2 */
// @flow
type User = {
  name: string,
  age: number
};
const user: User = { name: 'John', age: 30 };

Type Casting

This rule enforces a naming convention for type identifiers. The code sample demonstrates a type definition that follows the specified naming convention.

/* eslint flowtype/type-id-match: [2, "^([A-Z][a-z0-9]+)+Type$"] */
// @flow
type UserType = {
  name: string,
  age: number
};
const user: UserType = { name: 'John', age: 30 };

Other packages similar to eslint-plugin-flowtype

Readme

Source

eslint-plugin-flowtype

NPM version Travis build status js-canonical-style

Flow type linting rules for ESLint.

Installation

  1. Install ESLint.
  2. Install babel-eslint parser (ESLint parser does not support type annotations).
  3. Install eslint-plugin-flowtype plugin.
npm install eslint
npm install babel-eslint
npm install eslint-plugin-flowtype

Configuration

  1. Set parser property to babel-eslint.
  2. Add plugins section and specify eslint-plugin-flowtype as a plugin.
  3. Enable rules.
{
    "parser": "babel-eslint",
    "plugins": [
        "flowtype"
    ],
    "rules": {
        "flowtype/require-parameter-type": 1,
        "flowtype/require-return-type": 1,
        "flowtype/space-after-type-colon": 1,
        "flowtype/space-before-type-colon": 1
    }
}

Rules

require-parameter-type

Requires that all function parameters have type annotations.

The following patterns are considered problems:

(foo) => {}
// Message: Missing "foo" parameter type annotation.

(foo = 'FOO') => {}
// Message: Missing "foo" parameter type annotation.

(...foo) => {}
// Message: Missing "foo" parameter type annotation.

({foo}) => {}
// Message: Missing "{foo}" parameter type annotation.

The following patterns are not considered problems:

(foo: string) => {}

(foo: string = 'FOO') => {}

(...foo: string) => {}

({foo}: {foo: string}) => {}

require-return-type

Requires that functions have return type annotation.

The following patterns are considered problems:

(foo) => {}
// Message: Missing return type annotation.

The following patterns are not considered problems:

(foo): string => {}

space-after-type-colon

Enforces consistent spacing after the type annotation colon.

This rule takes one argument. If it is 'always' then a problem is raised when there is no space after the type annotation colon. If it is 'never' then a problem is raised when there is a space after the type annotation colon. The default value is 'always'.

The following patterns are considered problems:

// Options: ["never"]
(foo: string) => {}
// Message: There must be no space after "foo" parameter type annotation colon.

// Options: ["always"]
(foo:string) => {}
// Message: There must be a space after "foo" parameter type annotation colon.

// Options: ["always"]
(foo:  string) => {}
// Message: There must be 1 space after "foo" parameter type annotation colon.

The following patterns are not considered problems:

(foo) => {}

(foo: string) => {}

// Options: ["never"]
(foo:string) => {}

// Options: ["always"]
(foo: string) => {}

space-before-type-colon

Enforces consistent spacing before the type annotation colon.

This rule takes one argument. If it is 'always' then a problem is raised when there is no space before the type annotation colon. If it is 'never' then a problem is raised when there is a space before the type annotation colon. The default value is 'never'.

The following patterns are considered problems:

// Options: ["never"]
(foo : string) => {}
// Message: There must be no space before "foo" parameter type annotation colon.

// Options: ["always"]
(foo: string) => {}
// Message: There must be a space before "foo" parameter type annotation colon.

// Options: ["always"]
(foo  : string) => {}
// Message: There must be 1 space before "foo" parameter type annotation colon.

The following patterns are not considered problems:

(foo) => {}

(foo: string) => {}

// Options: ["never"]
(foo: string) => {}

// Options: ["always"]
(foo : string) => {}

eslint-plugin-flowtype v1

eslint-plugin-flowtype v1 served a different purpose:

A plugin for ESLint that strips FlowType type annonations before linting the files.

You can find the source code for v1 at:

https://github.com/gcazaciuc/eslint-plugin-flowtype

Reference to the original codebase included for historical reference purposes.

Keywords

FAQs

Package last updated on 22 Feb 2016

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc