Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork2.8k
fix(eslint-plugin): [no-deprecated] support for computed literal member access#11006
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
base:main
Are you sure you want to change the base?
fix(eslint-plugin): [no-deprecated] support for computed literal member access#11006
Uh oh!
There was an error while loading.Please reload this page.
Conversation
Thanks for the PR,@undsoft! 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 onhttps://opencollective.com/typescript-eslint. |
netlifybot commentedMar 28, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
✅ Deploy Preview fortypescript-eslint ready!
To edit notification comments on pull requests, go to yourNetlify site configuration. |
nx-cloudbot commentedMar 28, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
codecovbot commentedMar 28, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@## main #11006 +/- ##======================================= Coverage 90.82% 90.83% ======================================= Files 497 497 Lines 50204 50253 +49 Branches 8274 8289 +15 =======================================+ Hits 45600 45648 +48- Misses 4589 4590 +1 Partials 15 15
Flags with carried forward coverage won't be shown.Click here to find out more.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
🙌 Great start, thanks for kicking it off! I think there's just one case around[key]
that I think is still missing?
Uh oh!
There was an error while loading.Please reload this page.
…oft/typescript-eslint into 10958-string-literals-in-deprecated
undsoft commentedApr 4, 2025 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
@JoshuaKGoldberg constmyObject={/**@deprecated */recommended:null,};constkey='recommended';constk2='recom';constk3='mended';myObject[key];// WorksmyObject[`${k2}${k3}`];// Works However, more complex identifiers like: constmyObject={/**@deprecated */recommended:null,};constkey={nested:'recommended'}asconst;myObject[key.nested];// Doesn't work are not supported, because I feel like fixing this may be outside of the scope for this PR? Or otherwise I could use some guidance as to how to do this. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Really lovely progress! 💪
if (node.type === AST_NODE_TYPES.MemberExpression && node.computed) { | ||
return getComputedPropertyDeprecation(node); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
[Refactor]getComputedPropertyDeprecation
is already being called ingetDeprecationReason
, just after thegetCallLikeDeprecation
. If we swap the order to try the computed property check first then we'll be able to remove this call here:
if(node.type===AST_NODE_TYPES.MemberExpression&&node.computed){ | |
returngetComputedPropertyDeprecation(node); | |
} |
functiongetDeprecationReason(node:IdentifierLike):string|undefined{if(isInComputedProperty(node)){returngetComputedPropertyDeprecation(node.parentasTSESTree.MemberExpression,);}constcallLikeNode=getCallLikeNode(node);if(callLikeNode){returngetCallLikeDeprecation(callLikeNode);}
errors: [ | ||
{ | ||
column: 11, | ||
data: { name: 'key' }, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
[Bug]key
isn't deprecated,b
is. TypeScript correctly reports'b' is deprecated.
so the rule should too.
(here and elsewhere)
@@ -232,7 +266,7 @@ export default createRule<Options, MessageIds>({ | |||
} | |||
} | |||
function getCallLikeNode(node: TSESTree.Node):CallLikeNode | undefined { | |||
function getCallLikeNode(node: TSESTree.Node):CalleeNode | undefined { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
[Naming] If the type's name is switched fromCalleeNode
toCallLikeNode
, the correspondingget*
function's name should too:
functiongetCallLikeNode(node:TSESTree.Node):CalleeNode|undefined{ | |
functiongetCalleNode(node:TSESTree.Node):CalleeNode|undefined{ |
Agreed, yeah - I think it'd be good as a followup issue. |
…958-string-literals-in-deprecated
Okay, I believe I've addressed the comments. |
PR Checklist
Overview
Adds support for literal member access like
a['b']