/ts-extended-deprecation-plugin

A TypeScript Language Service plugin for detecting and highlighting deprecated symbols with annotations. Provides diagnostics and hover tooltips for deprecated symbols across TypeScript and JavaScript projects.

Primary LanguageTypeScriptMIT LicenseMIT

GitHub Actions Workflow Status NPM Version NPM Downloads

TS Extended Deprecation Plugin

A TypeScript Language Service Plugin for detecting and highlighting deprecated symbols in TypeScript and JavaScript projects.

Example Output

BEFORE AFTER
BEFORE: Deprecations are manually marked with comments and JSDoc, making them easy to miss.

AFTER: The plugin automatically highlights deprecated symbols directly in the code editor for immediate visibility.

Usage

Installation

You can install ts-extended-deprecation-plugin as an npm package:

# Install the package locally
npm install --save-dev ts-extended-deprecation-plugin

Or with Yarn:

yarn add -D ts-extended-deprecation-plugin

Note: If you're using Visual Studio Code, you'll have to use the first approach above, with a path to the module, or run the "TypeScript: Select TypeScript Version" command and choose "Use Workspace Version", or click the version number between "TypeScript" and 😃 in the lower-right corner. Otherwise, VS Code will not be able to find your plugin. See https://github.com/microsoft/TypeScript/wiki/Writing-a-Language-Service-Plugin#testing-locally

Configuration

To use this plugin in your TypeScript project, add it to your tsconfig.json:

{
    "compilerOptions": {
        "plugins": [
            {
                "name": "ts-extended-deprecation-plugin"
            }
        ]
    }
}

This configuration will enable the plugin and allow it to detect deprecated symbols in your TypeScript/JavaScript code.

How it Works

The ts-extended-deprecation-plugin hooks into the TypeScript Language Service, detecting any symbols marked with @deprecated in your project. When it finds a deprecated symbol, it does the following:

  1. Hover Tooltip: Displays a hover tooltip in your editor with a deprecation message.
  2. Diagnostics: Adds a warning to the diagnostics view with details about the deprecated symbol, file, and location.

Plugin Options

You can extend the functionality with custom options in tsconfig.json. Currently, this plugin works automatically without additional configurations, but future releases may allow more granular control over the behavior.

Example Scenario

Consider this code:

// In your file.ts
/**
 * @deprecated Use newFunction instead
 */
export function oldFunction() {
    // ...
}

// Usage in another file
import { oldFunction } from "./file";
oldFunction(); // <-- Hovering over this will display a deprecation warning

The plugin will display a strikethrough in your editor and provide a tooltip indicating that oldFunction is deprecated.

Performance Insights

The plugin is lightweight and integrates seamlessly with the TypeScript compiler, so it won’t impact performance noticeably, even in large projects.

Major Use Cases

  • Tracking Deprecated Code: Identify deprecated functions, classes, variables, and more in your project and ensure your codebase remains up to date.
  • Maintaining Code Quality: Warn developers about deprecated code and encourage the use of newer alternatives.
  • Cross-File Detection: Works across multiple files in large codebases, even when deprecated symbols are re-exported or aliased.

Troubleshooting

Why isn’t the plugin detecting deprecated symbols?

Ensure the following:

  1. The plugin is added to your tsconfig.json under compilerOptions.plugins.
  2. The symbol is marked with @deprecated in a comment right before the declaration.

How to view more details about deprecated symbols?

Warnings about deprecated symbols will appear in the diagnostics view in your IDE (such as VSCode). Hovering over the symbol will display the deprecation message in a tooltip.

Support the Developer

If you find this plugin useful, consider supporting its development:

"Buy Me A Coffee"

Maintainers


puj

Contributing

We welcome contributions to ts-extended-deprecation-plugin! Please see CONTRIBUTING.md for more details.