Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

eslint-plugin-deprecation

gund2.4mLGPL-3.0-or-later3.0.0TypeScript support: included

ESLint rule that reports usage of deprecated code

readme

eslint-plugin-deprecation

Test Workflow Release Workflow Maintainability Npm Npm Downloads Size License semantic-release

An ESLint plugin with rules reporting usage of deprecated code

Prerequisites

If you already use TypeScript and one or more rules from the typescript-eslint plugin, then eslint-plugin-deprecation will work out of the box without any additional dependencies or special configuration specified in this section. (This is because @typescript-eslint/plugin automatically contains @typescript-eslint/parser and your ESLint should already be configured with the parserOptions to work properly with TypeScript.)

Otherwise, in order for you to use this plugin, you must also install the following dependencies:

  • typescript
  • @typescript-eslint/parser

For example, if you use the npm package manager, then you would run the following command in the root of your project:

npm install --save-dev typescript @typescript-eslint/parser

Next, you must configure ESLint to parse TypeScript and include type information:

{
  "parser": "@typescript-eslint/parser",
  "parserOptions": {
    "ecmaVersion": 2020,
    "sourceType": "module",
    "project": "./tsconfig.json" // <-- Point to your project's "tsconfig.json" or create a new one.
  }
}

Install

For example, if you use the npm package manager, then you would run the following command in the root of your project:

npm install --save-dev eslint-plugin-deprecation

Setup

The easiest way to use this plugin is to extend from the recommended config, like this:

{
  "extends": [
    "plugin:deprecation/recommended",
  ],
}

The recommended config will enable the plugin and enable the deprecation/deprecation rule with a value of error.

Manually Enable the Plugin and Rule

If you don't want to use the recommended config for some reason, you can accomplish the same thing by specifying the following config:

{
  "plugins": [
    "deprecation",
  ],

  "rules": {
    "deprecation/deprecation": "error",
  },
}

Rules

Disallow usage of deprecated APIs (deprecation/deprecation)

Reports usage of any code marked with a @deprecated JSDoc tag.

For example, this includes browser APIs, Node.js APIs, library APIs and any other code that is marked with this tag.

Rule Details

Examples of incorrect code for this rule:

import { parse } from 'node:url';
import cheerio from 'cheerio';

// Node.js API
const url = parse('/foo'); // ❌ 'parse' is deprecated. Use the WHATWG URL API instead. eslint(deprecation/deprecation)

// Browser API
console.log(event?.bubbles); // ❌ 'event' is deprecated. [MDN Reference](https://developer.mozilla.org/docs/Web/API/Window/event) eslint(deprecation/deprecation)

// Deprecated library API
cheerio('<h2 class="title">Hello world</h2>'); // ❌ 'cheerio' is deprecated. Use the function returned by `load` instead. eslint(deprecation/deprecation)

Examples of correct code for this rule:

import { load } from 'cheerio';
import { ChangeEvent } from 'react';

// Node.js API
const url2 = new URL('/foo', 'http://www.example.com'); // ✅ Modern Node.js API, uses `new URL()`

// Browser API
function onClick(event: ChangeEvent<HTMLInputElement>) {
  console.log(event.bubbles); // ✅ Modern browser API, does not use global
}

// Library API
load('<h2 class="title">Hello world</h2>'); // ✅ Allowed library API, uses named `load` import

Credits

This rule was originally ported from the SonarJS repository.

changelog

Changelog

3.0.0 (2024-05-31)

Features

  • add plugin meta and support typescript-eslint@7 (#86) (1365f7f)

BREAKING CHANGES

  • Dropped support for ESLint v7.

  • feat: add plugin meta and support typescript-eslint@7

  • Update package.json

Co-authored-by: Alex Malkevich 3644678+gund@users.noreply.github.com

  • Updated lockfile and other dependencies

  • skipLibCheck too

  • Goodbye, ESLint v7

2.0.0 (2023-09-13)

Features

  • migrate to typescript-eslint/utils 6.x (#71) (5a32ce0)

BREAKING CHANGES

  • Dropped support for ESLint v6 and Typescript v3.7.5, please make sure to use at least ESLint v7 with Typescript v4.2 or downgrade to a previous major version.

1.5.0 (2023-07-27)

Features

  • add deprecation/recommended configuration (#69) (4b482c0), closes #68
  • recommended config (33a1888)

1.4.1 (2023-04-05)

Bug Fixes

  • deps: use @typescript-eslint/utils instead of experimental (448004c)

1.4.0 (2023-04-01)

Features

  • add support for Typescript v5 (a9683d9)

1.4.0-next.2 (2023-03-31)

Bug Fixes

1.4.0-next.1 (2023-02-22)

Features

  • deps: add Typescript v5 beta support (0d7e2a4)

1.3.3 (2022-11-14)

Bug Fixes

  • rule: optimize rule checks (bcffb64)

1.3.2 (2021-12-15)

Bug Fixes

  • rule: restore compatibility with ESLint <=v7 (daace2a)

1.3.1 (2021-12-14)

Bug Fixes

  • print deprecation reason correctly on ts 4.3+ (e3c3c47)

1.3.0 (2021-12-14)

Features

  • deps: update deps, support of eslint 8 (6cb798c)

1.2.1 (2021-05-04)

Bug Fixes

  • don't flag JSX closing tags (ea60c3d)

1.2.0 (2020-12-07)

Features

  • add ability to show rule for JSX usage (f60558c), closes #8

1.1.1 (2020-12-06)

Bug Fixes

  • package: allow Typescript v4 as a peer dependency (0e31d0c)

1.1.0 (2020-06-03)

Bug Fixes

Features

  • catch more deprecation cases and add tests (33eecd6)

1.0.1 (2020-05-04)

Bug Fixes

  • build: remove typescript from dependencies and keep it as peer dependency only (b724caf), closes #3

1.0.0 (2020-02-16)

Features