-
-
Notifications
You must be signed in to change notification settings - Fork 2.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 our terms of service and privacy 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
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 on https://opencollective.com/typescript-eslint. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
View your CI Pipeline Execution ↗ for commit 7223496.
☁️ Nx Cloud last updated this comment at |
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?
…oft/typescript-eslint into 10958-string-literals-in-deprecated
@JoshuaKGoldberg const myObject = {
/** @deprecated */
recommended: null,
};
const key = 'recommended';
const k2 = 'recom';
const k3 = 'mended';
myObject[key]; // Works
myObject[`${k2}${k3}`]; // Works However, more complex identifiers like: const myObject = {
/** @deprecated */
recommended: null,
};
const key = {
nested: 'recommended'
} as const;
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 in getDeprecationReason
, just after the getCallLikeDeprecation
. 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) { | |
return getComputedPropertyDeprecation(node); | |
} |
function getDeprecationReason(node: IdentifierLike): string | undefined {
if (isInComputedProperty(node)) {
return getComputedPropertyDeprecation(
node.parent as TSESTree.MemberExpression,
);
}
const callLikeNode = getCallLikeNode(node);
if (callLikeNode) {
return getCallLikeDeprecation(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 from CalleeNode
to CallLikeNode
, the corresponding get*
function's name should too:
function getCallLikeNode(node: TSESTree.Node): CalleeNode | undefined { | |
function getCalleNode(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']