Skip to content

feat(eslint-plugin): [no-deprecated] add allow options #10585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Jan 13, 2025

Conversation

yeonjuan
Copy link
Contributor

@yeonjuan yeonjuan commented Jan 1, 2025

PR Checklist

Overview

This PR addresses issue #9899.
Add an allow option of type TypeOrValueSpecifier. The types/values specified in the allow option are allowed to be used even if deprecated.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @yeonjuan!

typescript-eslint is a 100% community driven project, and we are incredibly grateful that you are contributing to that community.

The core maintainers work on this in their personal time, so please understand that it may not be possible for them to review your work immediately.

Thanks again!


🙏 Please, if you or your company is finding typescript-eslint valuable, help us sustain the project by sponsoring it transparently on https://opencollective.com/typescript-eslint.

Copy link

netlify bot commented Jan 1, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 4ee9616
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/677d6302257c5a0008b73ea2
😎 Deploy Preview https://deploy-preview-10585--typescript-eslint.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 100 (🟢 up 7 from production)
Accessibility: 100 (no change from production)
Best Practices: 92 (no change from production)
SEO: 98 (no change from production)
PWA: 80 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify site configuration.

Copy link

nx-cloud bot commented Jan 1, 2025

View your CI Pipeline Execution ↗ for commit 4ee9616.

Command Status Duration Result
nx test eslint-plugin --coverage=false ✅ Succeeded 7m 16s View ↗
nx test eslint-plugin ✅ Succeeded 5m 46s View ↗
nx test typescript-eslint --coverage=false ✅ Succeeded 19s View ↗
nx test utils --coverage=false ✅ Succeeded <1s View ↗
nx test scope-manager --coverage=false ✅ Succeeded <1s View ↗
nx test visitor-keys --coverage=false ✅ Succeeded <1s View ↗
nx run types:build ✅ Succeeded <1s View ↗
nx test type-utils --coverage=false ✅ Succeeded <1s View ↗
Additional runs (24) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-01-07 17:40:14 UTC

await apiV2();

function foo(
element: HTMLFrameSetElement, // HTMLFrameSetElement is deprecated (not specified in the option)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HTMLFrameSetElement is deprecated, so when I check it in the playground, it shows a lint error. However, snapshot tests don't show lint errors, so maybe this is a bug in the snapshot test tsconfig configuration?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hunch: that's from one including DOM types and the other not. I think switching this from a lib allow to a file or package allow would bypass that - and also be more representative of how most users would want to see this. But #9269 makes that hard because what we use in the playground isn't actually the same as docs and rule tests...

How about going with a @deprecated global from lib.es5.d.ts, maybe escape? http://localhost:3000/play#ts=5.7.2&fileType=.ts&code=KYZwxghgDsAUBEATgbwH-gSgFAFcB2okMCApAKIAsJAYgGw0DCmQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oBNFjpEZAIb5E3dGADa4bDkTRoHaJAA0M2VlnZIQ%2BPA4B3CdK1bNp2ZABmigLYTIjAEar1FnEyG3ED8kNKQbqYAvkHYALphobKREKHBQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Examples of code for this rule with:

```json
{
  "allow": [{ "from": "file", "name": "escape" }]
}
```

<Tabs>
<TabItem value="❌ Incorrect">

```ts option='{"allow":[{"from":"lib","name":"escape"}]}'
unescape('...');
```

</TabItem>

<TabItem value="✅ Correct">

```ts option='{"allow":[{"from":"file","name":"escape"}]}'
escape('...');
```

</TabItem>
</Tabs>

Copy link

codecov bot commented Jan 1, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.95%. Comparing base (d63ea3b) to head (4ee9616).
Report is 18 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #10585      +/-   ##
==========================================
+ Coverage   86.90%   86.95%   +0.04%     
==========================================
  Files         446      446              
  Lines       15505    15512       +7     
  Branches     4517     4519       +2     
==========================================
+ Hits        13475    13488      +13     
+ Misses       1675     1669       -6     
  Partials      355      355              
Flag Coverage Δ
unittest 86.95% <100.00%> (+0.04%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
packages/eslint-plugin/src/rules/no-deprecated.ts 94.33% <100.00%> (+0.22%) ⬆️

... and 3 files with indirect coverage changes

@yeonjuan yeonjuan marked this pull request as ready for review January 2, 2025 13:20
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionality looks stellar! Just discussing docs changes now I think.

await apiV2();

function foo(
element: HTMLFrameSetElement, // HTMLFrameSetElement is deprecated (not specified in the option)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hunch: that's from one including DOM types and the other not. I think switching this from a lib allow to a file or package allow would bypass that - and also be more representative of how most users would want to see this. But #9269 makes that hard because what we use in the playground isn't actually the same as docs and rule tests...

How about going with a @deprecated global from lib.es5.d.ts, maybe escape? http://localhost:3000/play#ts=5.7.2&fileType=.ts&code=KYZwxghgDsAUBEATgbwH-gSgFAFcB2okMCApAKIAsJAYgGw0DCmQA&eslintrc=N4KABGBEBOCuA2BTAzpAXGUEKQAIBcBPABxQGNoBLY-AWhXkoDt8B6Jge1oBNFjpEZAIb5E3dGADa4bDkTRoHaJAA0M2VlnZIQ%2BPA4B3CdK1bNp2ZABmigLYTIjAEar1FnEyG3ED8kNKQbqYAvkHYALphobKREKHBQA&tsconfig=N4KABGBEDGD2C2AHAlgGwKYCcDyiAuysAdgM6QBcYoEEkJemy0eAcgK6qoDCAFutAGsylBm3TgwAXxCSgA&tokens=false

Examples of code for this rule with:

```json
{
  "allow": [{ "from": "file", "name": "escape" }]
}
```

<Tabs>
<TabItem value="❌ Incorrect">

```ts option='{"allow":[{"from":"lib","name":"escape"}]}'
unescape('...');
```

</TabItem>

<TabItem value="✅ Correct">

```ts option='{"allow":[{"from":"file","name":"escape"}]}'
escape('...');
```

</TabItem>
</Tabs>

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Jan 7, 2025
@yeonjuan
Copy link
Contributor Author

yeonjuan commented Jan 7, 2025

@JoshuaKGoldberg Thanks! Fixed! 3b45f65

JoshuaKGoldberg
JoshuaKGoldberg previously approved these changes Jan 7, 2025
Copy link
Member

@JoshuaKGoldberg JoshuaKGoldberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shining gold five-pointed star with a light shine effect

"allow": [
{ "from": "file", "name": "apiV1" },
{ "from": "lib", "name": "escape" },
{ "from": "package", "name": "Bar", "package": "bar-lib" }
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: since the package isn't referenced in the examples..

Suggested change
{ "from": "package", "name": "Bar", "package": "bar-lib" }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh. Thanks!
4ee9616

@JoshuaKGoldberg JoshuaKGoldberg added 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge and removed awaiting response Issues waiting for a reply from the OP or another party labels Jan 7, 2025
Copy link
Member

@ronami ronami left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PR looks great, thank you 💯


Some thoughts:

Testing various cases, it seems TypeOrValueSpecifier is a bit more limited for the use-cases of this rule.

For example, I didn't manage to configure the allow option not to report these: 1, 2. I haven't used TypeOrValueSpecifier extensively, so this might be an oversight on my end.

@JoshuaKGoldberg
Copy link
Member

Yeah I suspect if this option gets a lot of usage, we'll get >=1 feature request to expand that format. 👍

@JoshuaKGoldberg JoshuaKGoldberg merged commit 6dda0a4 into typescript-eslint:main Jan 13, 2025
60 of 62 checks passed
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Jan 13, 2025
##### [v8.20.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8200-2025-01-13)

##### 🚀 Features

-   **eslint-plugin:** \[consistent-type-assertions] add arrayLiteralTypeAssertions options ([#10565](typescript-eslint/typescript-eslint#10565))
-   **eslint-plugin:** \[no-deprecated] add allow options ([#10585](typescript-eslint/typescript-eslint#10585))
-   **eslint-plugin:** \[no-misused-spread] add new rule ([#10551](typescript-eslint/typescript-eslint#10551))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] don't flag optional chaining for union types with an unconstrained type parameters ([#10602](typescript-eslint/typescript-eslint#10602))
-   **eslint-plugin:** \[no-shadow] ignore ordering of type declarations ([#10593](typescript-eslint/typescript-eslint#10593))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   Ronen Amiel
-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Jan 13, 2025
##### [v8.20.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8200-2025-01-13)

##### 🚀 Features

-   **eslint-plugin:** \[consistent-type-assertions] add arrayLiteralTypeAssertions options ([#10565](typescript-eslint/typescript-eslint#10565))
-   **eslint-plugin:** \[no-deprecated] add allow options ([#10585](typescript-eslint/typescript-eslint#10585))
-   **eslint-plugin:** \[no-misused-spread] add new rule ([#10551](typescript-eslint/typescript-eslint#10551))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] don't flag optional chaining for union types with an unconstrained type parameters ([#10602](typescript-eslint/typescript-eslint#10602))
-   **eslint-plugin:** \[no-shadow] ignore ordering of type declarations ([#10593](typescript-eslint/typescript-eslint#10593))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   Ronen Amiel
-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Jan 14, 2025
##### [v8.20.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8200-2025-01-13)

##### 🚀 Features

-   **eslint-plugin:** \[consistent-type-assertions] add arrayLiteralTypeAssertions options ([#10565](typescript-eslint/typescript-eslint#10565))
-   **eslint-plugin:** \[no-deprecated] add allow options ([#10585](typescript-eslint/typescript-eslint#10585))
-   **eslint-plugin:** \[no-misused-spread] add new rule ([#10551](typescript-eslint/typescript-eslint#10551))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] don't flag optional chaining for union types with an unconstrained type parameters ([#10602](typescript-eslint/typescript-eslint#10602))
-   **eslint-plugin:** \[no-shadow] ignore ordering of type declarations ([#10593](typescript-eslint/typescript-eslint#10593))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   Ronen Amiel
-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to mmkal/eslint-plugin-mmkal that referenced this pull request Jan 15, 2025
##### [v8.20.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8200-2025-01-13)

##### 🚀 Features

-   **eslint-plugin:** \[consistent-type-assertions] add arrayLiteralTypeAssertions options ([#10565](typescript-eslint/typescript-eslint#10565))
-   **eslint-plugin:** \[no-deprecated] add allow options ([#10585](typescript-eslint/typescript-eslint#10585))
-   **eslint-plugin:** \[no-misused-spread] add new rule ([#10551](typescript-eslint/typescript-eslint#10551))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] don't flag optional chaining for union types with an unconstrained type parameters ([#10602](typescript-eslint/typescript-eslint#10602))
-   **eslint-plugin:** \[no-shadow] ignore ordering of type declarations ([#10593](typescript-eslint/typescript-eslint#10593))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   Ronen Amiel
-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jan 15, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.19.1 | 8.20.0 |
| npm        | @typescript-eslint/parser        | 8.19.1 | 8.20.0 |


## [v8.20.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8200-2025-01-13)

##### 🚀 Features

-   **eslint-plugin:** \[consistent-type-assertions] add arrayLiteralTypeAssertions options ([#10565](typescript-eslint/typescript-eslint#10565))
-   **eslint-plugin:** \[no-deprecated] add allow options ([#10585](typescript-eslint/typescript-eslint#10585))
-   **eslint-plugin:** \[no-misused-spread] add new rule ([#10551](typescript-eslint/typescript-eslint#10551))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] don't flag optional chaining for union types with an unconstrained type parameters ([#10602](typescript-eslint/typescript-eslint#10602))
-   **eslint-plugin:** \[no-shadow] ignore ordering of type declarations ([#10593](typescript-eslint/typescript-eslint#10593))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   Ronen Amiel
-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
renovate bot added a commit to andrei-picus-tink/auto-renovate that referenced this pull request Jan 15, 2025
| datasource | package                          | from   | to     |
| ---------- | -------------------------------- | ------ | ------ |
| npm        | @typescript-eslint/eslint-plugin | 8.19.1 | 8.20.0 |
| npm        | @typescript-eslint/parser        | 8.19.1 | 8.20.0 |


## [v8.20.0](https://github.com/typescript-eslint/typescript-eslint/blob/HEAD/packages/eslint-plugin/CHANGELOG.md#8200-2025-01-13)

##### 🚀 Features

-   **eslint-plugin:** \[consistent-type-assertions] add arrayLiteralTypeAssertions options ([#10565](typescript-eslint/typescript-eslint#10565))
-   **eslint-plugin:** \[no-deprecated] add allow options ([#10585](typescript-eslint/typescript-eslint#10585))
-   **eslint-plugin:** \[no-misused-spread] add new rule ([#10551](typescript-eslint/typescript-eslint#10551))

##### 🩹 Fixes

-   **eslint-plugin:** \[no-unnecessary-condition] don't flag optional chaining for union types with an unconstrained type parameters ([#10602](typescript-eslint/typescript-eslint#10602))
-   **eslint-plugin:** \[no-shadow] ignore ordering of type declarations ([#10593](typescript-eslint/typescript-eslint#10593))

##### ❤️ Thank You

-   Josh Goldberg ✨
-   Ronen Amiel
-   YeonJuan [@yeonjuan](https://github.com/yeonjuan)

You can read about our [versioning strategy](https://main--typescript-eslint.netlify.app/users/versioning) and [releases](https://main--typescript-eslint.netlify.app/users/releases) on our website.
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

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