-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
feat(eslint-plugin): add rule call-super-on-override #5848
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
Conversation
I rewrite it again after one month, and i figured out that the last clone is outdated and i cloned the latest repo and just copied & pasted the file. Because of that there is no history available for this project.
Thanks for the PR, @mahdi-farnia! 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. As a thank you, your profile/company logo will be added to our main README which receives thousands of unique visitors per day. |
✅ Deploy Preview for typescript-eslint ready!
To edit notification comments on pull requests, go to your Netlify site settings. |
Codecov Report
Additional details and impacted files@@ Coverage Diff @@
## main #5848 +/- ##
==========================================
+ Coverage 85.15% 85.16% +0.01%
==========================================
Files 383 384 +1
Lines 13026 13057 +31
Branches 3839 3851 +12
==========================================
+ Hits 11092 11120 +28
Misses 1572 1572
- Partials 362 365 +3
Flags with carried forward coverage won't be shown. Click here to find out more.
|
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! I don't have time to work on this now, so leaving a review for now as usual. As discussed in #684 (comment), anybody can feel free to send a new PR addressing the review. ❤️
Unnecessary Information Removed Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
Rule Is Now Off By Default Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
My bad!😱 Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
This option is unneeded because users can simply turn off the rule
Support for literal method names & better error message for computed and non-computed method names.
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.
Getting closer, thanks for continuing to work on this! Unless someone in @typescript-eslint/triage-team disagrees with me, I think we'll want type checking in the rule?
if (node.key.type === AST_NODE_TYPES.Identifier) { | ||
methodName = node.key.name; | ||
} else { | ||
methodNameIsLiteral = true; |
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] Aha, a duplication of information! methodNameIsLiteral
will always be true
if methodNameIsNull
is true
. So this is using two variables to store a single piece of info. I'd suggest using either a union type or enum to consolidate down to one variable.
For example, the enum form might look something like this (but maybe with different names, I haven't thought too hard about these):
type MethodNameVariant = 'identifier' | 'non-null-literal' | 'null-literal';
// null & undefined can be used as property names, undefined counted as Identifier & null as Literal | ||
methodName = | ||
(node.key as TSESTree.Literal).value?.toString() ?? 'null'; | ||
methodNameIsNull = (node.key as TSESTree.Literal).value == null; |
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.
node.key as TSESTree.Literal
[Refactor] This as
assertion isn't always going to be correct. The TSESTree types are set up to represent all the possible values of properties. The fact that an as
was needed to get this code to type check means that the code isn't handling some case that it needs to handle.
Removing the as
gives:
Property 'value' does not exist on type 'FunctionExpression | ArrayExpression | ArrayPattern | ArrowFunctionExpression | AssignmentExpression | ... 35 more ... | YieldExpression'.
Property 'value' does not exist on type 'FunctionExpression'.
...which is true. What if the node's key is a function expression?
class InvalidSample {
[function () { }]() {
console.log("Yippee!")
}
}
This code is wacky (and causes a TypeScript complaint) but someone in the wild might try to run this rule on that code.
Change request: remove all the as
assertions from this file, and explicitly handle those odd node edge cases.
Note too that we require high unit test coverage (generally, ~100% if possible) for new rule tests. So this'll need unit tests added for any new logic. You can always run yarn test
from packages/eslint-plugin
to generate a testing coverage report at packages/eslint-plugin/coverage/lcov-report/index.html
(or see the Codecov PR comment for an online viewer).
|
||
## When Not To Use It | ||
|
||
When you are using TypeScript < 4.3 or you did not set `noImplicitOverride: true` in `CompilerOptions` |
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.
A lot of consumers don't use noImplicitOverride
. I think we'll still want the rule to be able to work for them... which means it'll have to use rule type checking when there isn't an override
operator on a method.
Roughly, that means:
- Grabbing the type of the extended class
- Checking whether it has a method / function property under the same name
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.
Let's keep conversations threaded, please, so it's easier to have multiple at a time & mark them as open or resolved.
As to how to grab the type of the extended class: you'll need to use the type checker. Have you read our resources on doing that?
👋 @mahdi-farnia! Just checking in, is this still something you have time for? No worries if not - I just don't want to leave it hanging. |
I'll name this laziness of myself Sorry about that I forgot resolving issues after my college exams...🤦♂️ |
Co-authored-by: Josh Goldberg <git@joshuakgoldberg.com>
☁️ Nx Cloud ReportCI is running/has finished running commands for commit 2b97414. As they complete they will appear below. Click to see the status, the terminal output, and the build insights. 📂 See all runs for this branch
✅ Successfully ran 24 targets
Sent with 💌 from NxCloud. |
I need help! |
Commit current progress (for now)
Just note that i did not make any progress (for now). I already using astexplorer and ts-ast-viewer Is there any other tool? |
I responded in this thread: #5848 (comment) |
PR Checklist
Overview
Before:
After:
Before:
After:
Closes #684