Skip to content

feat(eslint-plugin): [no-base-to-string] add checkUnknown Option #11128

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

Open
wants to merge 6 commits into
base: main
Choose a base branch
from

Conversation

developer-bandi
Copy link
Contributor

@developer-bandi developer-bandi commented May 4, 2025

PR Checklist

Overview

add checkUnknown option.

One thing I'm curious about is, is it correct to treat generic types as unknown?

function foo<T>(x: T) {
  String(x);
}

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @developer-bandi!

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.

@developer-bandi developer-bandi marked this pull request as draft May 4, 2025 15:33
Copy link

netlify bot commented May 4, 2025

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 80fd6d8
🔍 Latest deploy log https://app.netlify.com/projects/typescript-eslint/deploys/6842525cb1d7fd000893903b
😎 Deploy Preview https://deploy-preview-11128--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: 98 (🔴 down 1 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (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 project configuration.

Copy link

nx-cloud bot commented May 4, 2025

View your CI Pipeline Execution ↗ for commit 80fd6d8.

Command Status Duration Result
nx test eslint-plugin --coverage=false ✅ Succeeded 5m 1s View ↗
nx run-many -t typecheck ✅ Succeeded 2m 9s View ↗
nx run-many -t lint ✅ Succeeded 14s View ↗
nx run generate-configs ✅ Succeeded 8s View ↗
nx test eslint-plugin-internal --coverage=false ✅ Succeeded <1s View ↗
nx run types:build ✅ Succeeded <1s View ↗
nx test typescript-estree --coverage=false ✅ Succeeded <1s View ↗
nx run integration-tests:test ✅ Succeeded <1s View ↗
Additional runs (27) ✅ Succeeded ... View ↗

☁️ Nx Cloud last updated this comment at 2025-06-06 02:39:48 UTC

@developer-bandi developer-bandi marked this pull request as ready for review May 6, 2025 06:18
@JoshuaKGoldberg JoshuaKGoldberg changed the title feat(eslint-plugin): [no-base-to-string] add restrictUnknown Option feat(eslint-plugin): [no-base-to-string] add checkUnknown Option May 12, 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.

LGTM, thanks!

Could you please get a passing CI so we can merge this though?

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.

(wrong button)

Copy link

codecov bot commented May 18, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 90.91%. Comparing base (bca8a91) to head (80fd6d8).
Report is 86 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11128      +/-   ##
==========================================
+ Coverage   90.84%   90.91%   +0.07%     
==========================================
  Files         497      501       +4     
  Lines       50320    50879     +559     
  Branches     8311     8385      +74     
==========================================
+ Hits        45714    46258     +544     
- Misses       4591     4606      +15     
  Partials       15       15              
Flag Coverage Δ
unittest 90.91% <100.00%> (+0.07%) ⬆️

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

Files with missing lines Coverage Δ
...kages/eslint-plugin/src/rules/no-base-to-string.ts 98.94% <100.00%> (+0.03%) ⬆️

... and 29 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@developer-bandi
Copy link
Contributor Author

LGTM, thanks!

Could you please get a passing CI so we can merge this though?

I added an option description to the document because there was an error that occurred not only in the CI error but also in the document due to not adding the option.

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.

LGTM, thanks! 🚀

Just a couple small comment on the meta property, nothing we can't touch up before merge.

type: 'boolean',
default: false,
description:
'Checks the case where toString is applied to unknown type',
Copy link
Member

Choose a reason for hiding this comment

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

[Docs] A little bit of phrasing alignment:

Suggested change
'Checks the case where toString is applied to unknown type',
'Whether to also check values of type `unknown`',

@@ -46,6 +47,12 @@ export default createRule<Options, MessageIds>({
type: 'object',
additionalProperties: false,
properties: {
checkUnknown: {
type: 'boolean',
default: false,
Copy link
Member

Choose a reason for hiding this comment

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

[Cleanup] This actually doesn't do anything in our stack (long story...)

Suggested change
default: false,

@JoshuaKGoldberg JoshuaKGoldberg added the 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge label May 19, 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.

🚀🚀 Looking great, thank you! I've added a couple of comments around documentation and testing.

Comment on lines 109 to 110
declare const x: unknown;
x.toString();
Copy link
Member

Choose a reason for hiding this comment

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

[Docs] The example above already shows a type error (and so it's less likely to happen). What do you think about something along the following (similar to the one in the original issue):

declare const x: unknown;
String(x);

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I also think the above code is more suitable as an example. thank you.

if (!toString) {
// e.g. any/unknown
// unknown
if (option.checkUnknown && type.flags === ts.TypeFlags.Unknown) {
Copy link
Member

Choose a reason for hiding this comment

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

[Tests] Removing type.flags === ts.TypeFlags.Unknown doesn't seem to fail any test, let's simplify or add a test case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

add any type test case. if we remove type.flags === ts.TypeFlags.Unknown, any type return Usefulness.Sometimes;

@kirkwaiblinger kirkwaiblinger added the awaiting response Issues waiting for a reply from the OP or another party label May 30, 2025
@developer-bandi developer-bandi requested a review from ronami June 1, 2025 10:53
@github-actions github-actions bot removed 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge awaiting response Issues waiting for a reply from the OP or another party labels Jun 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [no-base-to-string] False negative for unknown type
4 participants
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy