2.0.0 • Published 3 months ago

eslint-plugin-explicit-generics v2.0.0

Weekly downloads
-
License
ISC
Repository
github
Last release
3 months ago

eslint-plugin-explicit-generics

A TypeScript ESLint plugin to enforce generics input on specific functions

Installation

npm install eslint-plugin-explicit-generics @typescript-eslint/parser

Update ESLint Configuration

Add the plugin and provide the names of the functions you wish to enforce explicit setting of TypeScript generics on

  // .eslintrc.json
  ...
  "parser": "@typescript-eslint/parser",
  "plugins": ["explicit-generics"],
  "rules": {
    "explicit-generics/explicit-generics": ["error", { functionNames: ["functionName1", "functionName2"] }]
  }
  ...

Example

Let's assume we made this function that accepts generics

function foo<T,K>(arg1: T): K {
    ...
}

Now we want ESLint to force us to input the generics on each function call

// .eslintrc.json

  ...
  "parser": "@typescript-eslint/parser",
  "plugins": ["explicit-generics"],
  "rules": {
    "explicit-generics/explicit-generics": ["error", {functionNames: ["foo"]}]
  }
...

This will give these linting results

// Invalid:

foo(arg) // error  'foo' should include generics in function call


// Valid:

foo<string, number>(arg)
2.0.0

3 months ago

1.0.5

3 months ago

1.0.4

3 months ago

1.0.3

3 months ago

1.0.2

3 months ago

1.0.1

3 months ago

1.0.0

3 months ago