Skip to content

Enhancement: [no-deprecated] Add 'allow' option for specific types or values #9899

Closed
@BurningEnlightenment

Description

@BurningEnlightenment

Before You File a Proposal Please Confirm You Have Done The Following...

My proposal is suitable for this project

  • I believe my proposal would be useful to the broader TypeScript community (meaning it is not a niche proposal).

Link to the rule's documentation

https://typescript-eslint.io/rules/no-deprecated/

Description

I find it very useful to flag and address deprecated API usage during the dependency upgrade cycle. Whence I'd like to enforce the rule for the usage of my dependencies.
However, for my own code base I want to follow a gradual deprecation cycle, i.e. I want to introduce an updated API and inform users writing new code about the updated API via a @deprecated JSDoc comment. Afterwards I'd phase the deprecated API out and remove it in the end.
The current rule is unsuited for the combined requirements, so I propose a boolean option ignoreUserDeprecations.

Fail

/** @deprecated Use apiV2 instead. */
async function apiV1(): Promise<void> { /*…*/ }

async function apiV2(): Promise<void> { /*…*/ }

await apiV1();

/* >===================================< */

import { parse } from 'node:url';

// 'parse' is deprecated. Use the WHATWG URL API instead.
const url = parse('/foo');

Pass

/** @deprecated Use apiV2 instead. */
async function apiV1(): Promise<void> { /*…*/ }

async function apiV2(): Promise<void> { /*…*/ }

// apiV1 has been defined in the current code base and is therefore not flagged
await apiV1();

/* >===================================< */

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

Additional Info

Originally proposed in the [no-deprecated] issue #8988 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    accepting prsGo ahead, send a pull request that resolves this issueenhancement: plugin rule optionNew rule option for an existing eslint-plugin rulelocked due to agePlease open a new issue if you'd like to say more. See https://typescript-eslint.io/contributing.package: eslint-pluginIssues related to @typescript-eslint/eslint-plugin

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions