# eslint-plugin-require-explicit-generics

> Force configured functions to include explicit generics

Latest version **1.0.0** (published 2023-11-12) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-require-explicit-generics
pnpm add eslint-plugin-require-explicit-generics
yarn add eslint-plugin-require-explicit-generics
bun add eslint-plugin-require-explicit-generics
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2023-11-12 |
| First published | 2021-09-13 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 14 |
| Maintainers | morchard |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-require-explicit-generics
- Repository: https://github.com/mattorchard/eslint-plugin-require-explicit-generics
- Issues: https://github.com/mattorchard/eslint-plugin-require-explicit-generics/issues
- npm.io page: https://npm.io/package/eslint-plugin-require-explicit-generics

## Recent versions

- 1.0.0 (latest) — 2023-11-12
- 0.4.2 — 2022-06-07
- 0.4.1 — 2022-04-21
- 0.4.0 — 2022-04-21
- 0.3.0 — 2022-02-18
- 0.2.1 — 2021-09-14
- 0.1.0 — 2021-09-13

## README

# eslint-plugin-require-explicit-generics
Allow configured functions to require explicit generics.

## Why?
Some libraries are over-permissive with their types, allowing generics to be omitted defaulting them to the `any` type.
To prevent accidentally relying on this behaviour:
this plugin allows you to specify a list of functions and constructors that **MUST** have explicit generics set.

## Example
If you list `myFunction` in your `.eslintrc.js`:
```ts
myFunction(); // ❌ ESLint: Function 'myFunction' must be called with explicit generics...
myFunction<SomeType>(); // ✅ ESLint: Pass
```

## Installation
First install [ESLint](http://eslint.org/):
```shell
# npm 
npm install eslint --save-dev
# yarn 
yarn add eslint --dev
```
Next, install `eslint-plugin-require-explicit-generics`
```shell
# npm
npm install eslint-plugin-require-explicit-generics --save-dev
# yarn
yarn add eslint-plugin-require-explicit-generics --dev
```

## Configuration (REQUIRED)
In your `.estlintrc.js` add `"require-explicit-generics"` to the plugin list.
```js
plugins: [
  "require-explicit-generics",
],
```
Then in the rules section set `"require-explicit-generics/require-explicit-generics"`
pass the log level  (either `"error"` or `"warning"`),
then the list of functions to check.
```js
rules: {
  "require-explicit-generics/require-explicit-generics": [
    "error",
    // List your functions here
    [ "myFunction", "myVar.myOtherFunction" ]
  ]
},
```
You can also use a map to define how many generics to expect for each function.
```js
rules: {
  "require-explicit-generics/require-explicit-generics": [
    "error",
    { "myFunction": 3, "myVar.myOtherFunction": 1 }
  ]
},
```
```ts
myVar.myOtherFunction(); // Function 'myVar.myOtherFunction' must be called with generics...
myFunction<TypeA>(); // Function 'myOtherFunction' called with too few explicit generics...
```

---
_Source: https://npm.io/package/eslint-plugin-require-explicit-generics · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
