An ESLint plugin to limit the usage of 'any' types in TypeScript. It helps to enforce strict typing and improve code quality.
First, you need to install ESLint:
npm i eslint --save-dev
Next, install eslint-plugin-limit-any:
npm install eslint-plugin-limit-any --save-dev
The count rule limits the number of 'any' types in your TypeScript code. You can configure this rule in your ESLint configuration file.
// eslint.config.js
"use strict";
const tsParser = require("@typescript-eslint/parser");
// Import the ESLint plugin locally
const limitAnyRule = require("eslint-plugin-limit-any");
module.exports = [
{
files: ["**/*.ts"],
languageOptions: {
parser: tsParser,
sourceType: "commonjs",
ecmaVersion: "latest",
},
plugins: { "limit-any": limitAnyRule },
rules: {
"limit-any/count": ["error", 4],
},
},
];
//.eslintrc.json
{
"root": true,
"env": {
"node": true
},
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint", "limit-any"],
"extends": [
"eslint:recommended",
"plugin:@typescript-eslint/eslint-recommended",
"plugin:@typescript-eslint/recommended"
],
"rules": {
"limit-any/count": ["error", 4]
}
}