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
feat(eslint-plugin): [no-unsafe-call][no-unsafe-member-access] improve report messages for this
for noImplicitThis
#3199
Conversation
Thanks for the PR, @JounQin! 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. |
Codecov Report
@@ Coverage Diff @@
## master #3199 +/- ##
==========================================
- Coverage 92.91% 92.89% -0.03%
==========================================
Files 316 317 +1
Lines 10854 10905 +51
Branches 3069 3085 +16
==========================================
+ Hits 10085 10130 +45
- Misses 342 343 +1
- Partials 427 432 +5
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.
we can actually tell if the config option is turned on!
We should only report this message if the option is turned off
Here's an example of another rule checking if strictNullChecks
is turned on:
typescript-eslint/packages/eslint-plugin/src/rules/strict-boolean-expressions.ts
Lines 114 to 117 in 9273441
const isStrictNullChecks = tsutils.isStrictCompilerOptionEnabled( | |
compilerOptions, | |
'strictNullChecks', | |
); |
I think if we're going explicitly display this then we should be sure that this
is the cause and not something else.
eg we should only display the specific message if:
- the "thing" is a member expression on
any
noImplicitThis
is turned offthis
is of typeany
If any of these conditions is false - then we should use the normal message as we can tell that noImplicitThis
is not the cause.
@bradzacher Thanks! I'll add the option check. And the other two conditions has been checked, isn't it? |
Depends on the rule. For example, no unsafe call - And this only compounds the more members you add ofc. For no unsafe member - |
I'm still confused, I've already added checking whether the caller/member parent is |
you did check if it was an expression around For Which means that it will error in this case: class Foo {
foo: any;
method() {
this.foo();
}
} In this case saying "try turning on OTOH, it is correct to say "try turning on
For Eg imagine Does that make sense? |
OK, maybe I get your point now. |
Correct! To triple clarify for you: To save me copy-pasting these strings, the messageIds:
class Foo {
bar: any;
method() {
this.bar(); // no-unsafe-call: unsafeCall
this.bar.baz() // no-unsafe-call: unsafeCall
// no-unsafe-member-access: unsafeMemberExpression {property: baz}
this.bar.baz.bam // no-unsafe-member-access: unsafeMemberExpression {property: baz}
}
} // noImplicitThis: false
const Obj = {
method() {
this.bar(); // no-unsafe-call: unsafeCallThis
// no-unsafe-member-access: unsafeThisMemberExpression {property: bar}
this.bar.baz() // no-unsafe-call: unsafeCallThis
// no-unsafe-member-access: unsafeThisMemberExpression {property: bar}
this.bar.baz.bam // no-unsafe-member-access: unsafeThisMemberExpression {property: bar}
},
}; With There is this one special case which would exist with function anyThisFn(this: any) {
this.bar(); // no-unsafe-call: unsafeCallThis
// no-unsafe-member-access: unsafeThisMemberExpression {property: bar}
this.bar.baz() // no-unsafe-call: unsafeCallThis
// no-unsafe-member-access: unsafeThisMemberExpression {property: bar}
this.bar.baz.bam // no-unsafe-member-access: unsafeThisMemberExpression {property: bar}
}; |
@bradzacher How about current implementation? |
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.
almost there! Just a few comments.
Thanks for your work on this!
check no-unsafe-assignment and no-unsafe-return too
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.
LGTM - thanks for your contribution!
this
call and member-accessthis
for noImplicitThis
close #3197