1.0.2 • Published 6 years ago

eslint-plugin-types v1.0.2

Weekly downloads
146
License
ISC
Repository
github
Last release
6 years ago

eslint-plugin-types

A type checking plugin for eslint.

Installation

You'll first need to install ESLint:

$ npm i eslint --save-dev

Next, install eslint-plugin-types:

$ npm install eslint-plugin-types --save-dev

Note: If you installed ESLint globally (using the -g flag) then you must also install eslint-plugin-types globally.

Usage

Add types to the plugins section of your .eslintrc configuration file. You can omit the eslint-plugin- prefix:

{
    "plugins": [
        "types"
    ]
}

Then configure the rules you want to use under the rules section.

{
    "rules": {
        "types/assign-type": 2,
        "types/array-type": 2
    }
}

Supported Rules

assign-type

Variables must not change type once declared.

Correct:

let a = 'one';
a = 'two';

function example1 () {
    let a = 1;
    a = 2;
}

function example2 () {
    a = 'three';
}

Incorrect:

let a = '1';
a = 2; // error

array-type

Arrays items must be a consistent type.

Correct:

let a = [1, 2];
a.push(3);
a[2] = 4;

Incorrect:

let a = [1, 2, '3']; // error
a.push('4'); // error
a[3] = '5'; // error

let b = [];
b.push(1);
b.push('2'); // error
1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago

0.0.9

6 years ago

0.0.8

6 years ago

0.0.7

6 years ago

0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago