Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mattorchard/eslint-plugin-require-explicit-generics
https://github.com/mattorchard/eslint-plugin-require-explicit-generics
eslint eslint-plugin
Last synced: 7 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/mattorchard/eslint-plugin-require-explicit-generics
- Owner: mattorchard
- Created: 2021-09-13T00:34:10.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-11-12T02:01:49.000Z (12 months ago)
- Last Synced: 2024-10-29T08:31:32.609Z (8 days ago)
- Topics: eslint, eslint-plugin
- Language: JavaScript
- Homepage: https://www.npmjs.com/package/eslint-plugin-require-explicit-generics
- Size: 15.6 KB
- Stars: 13
- Watchers: 2
- Forks: 2
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
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(); // ✅ 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(); // Function 'myOtherFunction' called with too few explicit generics...
```