ESLint rule that reports usage of deprecated code marked with JSDoc @deprecated tags
—
Quality
Pending
Does it follow best practices?
Impact
Pending
No eval scenarios have been run
Pending
The risk profile of this skill
ESLint Plugin Deprecation provides rules that detect and report usage of deprecated code marked with JSDoc @deprecated tags. It works with TypeScript and JavaScript codebases to identify deprecated APIs from browsers, Node.js, libraries, and user-defined code.
npm install --save-dev eslint-plugin-deprecationESLint plugins are typically loaded automatically by ESLint when specified in configuration. For programmatic access:
import plugin from "eslint-plugin-deprecation";CommonJS import:
const plugin = require("eslint-plugin-deprecation");Access individual components:
import { rules, configs, meta } from "eslint-plugin-deprecation";The simplest setup uses the recommended configuration:
{
"extends": ["plugin:deprecation/recommended"]
}{
"plugins": ["deprecation"],
"rules": {
"deprecation/deprecation": "error"
}
}This plugin requires TypeScript parser configuration:
{
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2020,
"sourceType": "module",
"project": "./tsconfig.json"
}
}Main plugin export containing rules, configurations, and metadata.
interface PluginExport {
rules: {
deprecation: DeprecationRule;
};
configs: {
recommended: RecommendedConfig;
};
meta: {
name: string;
version: string;
};
}The core rule that detects usage of deprecated APIs.
interface DeprecationRule {
meta: {
type: "problem";
docs: {
description: "Do not use deprecated APIs.";
requiresTypeChecking: true;
};
messages: {
deprecated: "'{{name}}' is deprecated. {{reason}}";
};
schema: [];
};
defaultOptions: [];
create: (context: ESLintRuleContext) => {
Identifier: (node: ESLintNode) => void;
JSXIdentifier: (node: ESLintNode) => void;
};
}Rule Options: This rule takes no options.
What it detects:
@deprecated JSDoc tagsWhat it ignores:
Pre-configured ESLint configuration for immediate use.
interface RecommendedConfig {
plugins: string[];
rules: {
"deprecation/deprecation": "error";
};
}type ESLintRuleContext = {
getAncestors: () => ESLintNode[];
getParserServices: () => ParserServices;
report: (descriptor: {
node: ESLintNode;
messageId: string;
data: Record<string, string>;
}) => void;
};
type ESLintNode = {
type: string;
name?: string;
parent?: ESLintNode;
};
type ParserServices = {
program: TypeScriptProgram;
esTreeNodeToTSNodeMap: WeakMap<ESLintNode, TypeScriptNode>;
};
type TypeScriptProgram = {
getTypeChecker: () => TypeScriptTypeChecker;
};
type TypeScriptNode = unknown;
type TypeScriptTypeChecker = unknown;
type MessageIds = "deprecated";
type Options = unknown[];When the rule detects deprecated usage, it reports:
'{{name}}' is deprecated. {{reason}}Where:
{{name}} is the name of the deprecated API{{reason}} is the deprecation message from the @deprecated JSDoc tagConfiguration Error: If TypeScript services are not properly configured, the rule throws:
TypeScript is required for this rule: https://github.com/gund/eslint-plugin-deprecation#prerequisitesPeer Dependencies:
eslint: ^8.0.0typescript: ^4.2.4 || ^5.0.0Runtime Dependencies:
@typescript-eslint/utils: ^7.0.0tslib: ^2.3.1ts-api-utils: ^1.3.0Install with Tessl CLI
npx tessl i tessl/npm-eslint-plugin-deprecation