0.0.14 • Published 3 years ago

@mkusaka/eslint-plugin-prefer-type-annotate v0.0.14

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

eslint-plugin-prefer-type-annotate

Prefer add annotate for check any inferred point eslint rule.

install

type anotate

npm install --save-dev @mkusaka/eslint-plugin-prefer-type-annotate
yarn add -D @mkusaka/eslint-plugin-prefer-type-annotate

config

.eslintrc.js

module.exports = {
  parser: "@typescript-eslint/parser",
  parserOptions: {
    ecmaVersion: 2020,
    sourceType: "module",
    project: "tsconfig.json", // these rules require type infomation
  },
  extends: [
    // "plugin:@mkusaka/prefer-type-annotaten/all-error-rules", // include all rule as error
    "plugin:@mkusaka/prefer-type-annotate/all-warn-rules", // include all rule as error
  ],
  plugins: [
    "@mkusaka/prefer-type-annotate",
  ],
  rules: {
    // you can also manually enable specific rule and disable it.
    // "@mkusaka/prefer-type-annotate/arrow-function-expression": "off"
  },
};

Motivation

In cases when the noInplicitAny CompileOption off ts environment, function or variable declaration are sometime inferred to any type.

Since any type is very dangerous (it brake TypeScript typesystem..), most of TypeScript developer want to enable noImplicitAny compiler option.

So, some project, like gradually converting from js to ts all project files, must annotate implicit any before noImplicitAny to true.

But, implicit any detection are sometime too difficult.

To detect no implicit any and destroy it gradually, eslint is best solution of that. But, there is no good rule for this problem. (typedef rule can't detect inferred type information.)

Rule Details

Examples of incorrect code for this rule:

let a;

const b = (c, d) => c + d

function e(f, g) {
  return f / g
}

Examples of correct code for this rule:

let a: string

const b = (c: number, d: number) => c + d

function e(f: number, g: number) {
  return f / g
}

TODO

Add test for each rule.

0.0.14

3 years ago

0.0.10

3 years ago

0.0.11

3 years ago

0.0.12

3 years ago

0.0.13

3 years ago

0.0.9

3 years ago

0.0.8

3 years ago

0.0.6

3 years ago

0.0.5

3 years ago

0.0.4

3 years ago

0.0.3

4 years ago

0.0.3-beta.3

4 years ago

0.0.3-beta.2

4 years ago

0.0.3-beta.1

4 years ago

0.0.3-beta.0

4 years ago

0.0.3-0

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago