Skip to content
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

fix(eslint-plugin): [no-unnecessary-type-assertion] handle literal types #10523

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

Conversation

mdm317
Copy link
Contributor

@mdm317 mdm317 commented Dec 19, 2024

PR Checklist

Overview

Add case when cast type is a template literal or a union type that is string-like.

@typescript-eslint
Copy link
Contributor

Thanks for the PR, @mdm317!

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.

@mdm317 mdm317 marked this pull request as draft December 19, 2024 16:00
Copy link

netlify bot commented Dec 19, 2024

Deploy Preview for typescript-eslint ready!

Name Link
🔨 Latest commit 4c45f10
🔍 Latest deploy log https://app.netlify.com/sites/typescript-eslint/deploys/677634b367d5db00088dad84
😎 Deploy Preview https://deploy-preview-10523--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 (🟢 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 Dec 19, 2024

View your CI Pipeline Execution ↗ for commit 4c45f10.

Command Status Duration Result
nx run-many --target=build --exclude website --... ✅ Succeeded 5s View ↗
nx run-many --target=clean ✅ Succeeded 10s View ↗

☁️ Nx Cloud last updated this comment at 2025-01-03 01:57:55 UTC

Copy link

codecov bot commented Dec 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.90%. Comparing base (4dbf48b) to head (4c45f10).
Report is 2 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main   #10523   +/-   ##
=======================================
  Coverage   86.90%   86.90%           
=======================================
  Files         446      446           
  Lines       15502    15504    +2     
  Branches     4516     4517    +1     
=======================================
+ Hits        13472    13474    +2     
  Misses       1675     1675           
  Partials      355      355           
Flag Coverage Δ
unittest 86.90% <100.00%> (+<0.01%) ⬆️

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

Files with missing lines Coverage Δ
...-plugin/src/rules/no-unnecessary-type-assertion.ts 98.00% <100.00%> (+0.04%) ⬆️

@mdm317 mdm317 marked this pull request as ready for review December 20, 2024 11:53
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! Just requesting changes on naming and removing the noFormat. Thanks!

@@ -358,6 +358,16 @@ if (Math.random()) {
x!;
`,
},
"let a = (Date.now() % 2 ? 'a' : 'b') as 'a' | 'b';",
noFormat`
Copy link
Member

Choose a reason for hiding this comment

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

[Style] The added doesn't involve formatting/layout nuance, so there's no need to noFormat in them:

Suggested change
noFormat`
`

const wouldSameTypeBeInferred = castType.isLiteral()
? isImplicitlyNarrowedConstDeclaration(node)
: !isConstAssertion(node.typeAnnotation);
const isCastTypeTemplateLiteral =
Copy link
Member

Choose a reason for hiding this comment

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

[Docs] #10472

Suggested change
const isCastTypeTemplateLiteral =
const isAssertionTypeTemplateLiteral =

@JoshuaKGoldberg JoshuaKGoldberg added the awaiting response Issues waiting for a reply from the OP or another party label Dec 30, 2024
@mdm317 mdm317 requested a review from JoshuaKGoldberg January 2, 2025 13:46
@github-actions github-actions bot removed the awaiting response Issues waiting for a reply from the OP or another party label Jan 2, 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.

🪨

@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 Jan 2, 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! Just requesting minor changes around testing 🏆

Edit: I'm not sure if it's too fringe, but I did see one regression with the readonly modifier (main branch playground link, deploy preview playground link).


const wouldSameTypeBeInferred =
castType.isLiteral() ||
isAssertionTypeTemplateLiteral ||
Copy link
Member

Choose a reason for hiding this comment

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

[Testing]: No tests fail if this is omitted (isAssertionTypeTemplateLiteral ||), let's simplify or add a test case?

@JoshuaKGoldberg JoshuaKGoldberg added awaiting response Issues waiting for a reply from the OP or another party and removed 1 approval >=1 team member has approved this PR; we're now leaving it open for more reviews before we merge labels Jan 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting response Issues waiting for a reply from the OP or another party
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: [no-unnecessary-type-assertion] False report with an 'as' assertion
3 participants