-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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): [strict-boolean-expressions] consider assertion function argument a boolean context #9074
base: main
Are you sure you want to change the base?
Conversation
Thanks for the PR, @kirkwaiblinger! 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. |
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.
I squinted at the logic a bunch and it all seems pretty reasonable. Nice stuff. Requesting changes to add some tests just to be sure though. ✨
firstParameter != null && | ||
firstParameter.name.kind === ts.SyntaxKind.Identifier && |
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.
[Style] Nit: I'm always surprised we don't have a rule for this ... somewhere.
firstParameter != null && | |
firstParameter.name.kind === ts.SyntaxKind.Identifier && | |
firstParameter?.name.kind === ts.SyntaxKind.Identifier && |
? declaration.parameters.slice(1) | ||
: declaration.parameters; | ||
|
||
// Don't even bother inspecting parameters past the number of |
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.
[Docs] This is very nitpicky, but unnecessary _"even"_s have always bugged me.
// Don't even bother inspecting parameters past the number of | |
// Don't bother inspecting parameters past the number of |
declare function myAssert(value: unknown): asserts value; | ||
let maybeString = Math.random() > 0.5 ? '' : undefined; | ||
myAssert(maybeString); |
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.
[Docs] Nit: everywhere else generally refers to assert()
, and that's a pretty commonly used name. I think it'd be nice to use it here for consistency.
declare function myAssert(value: unknown): asserts value; | |
let maybeString = Math.random() > 0.5 ? '' : undefined; | |
myAssert(maybeString); | |
declare function assert(value: unknown): asserts value; | |
let maybeString = Math.random() > 0.5 ? '' : undefined; | |
assert(maybeString); |
const assertedParameter = checkableArguments[assertedParameterIndex]; | ||
traverseNode(assertedParameter, 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] Totally optional, but I had a bit of a hard time figuring out the intended flow of all the added code. There's a lot. Extracting out the "what is the asserted parameter index?" logic into a separate might be helpful in making that more clear. What do you think?
const assertedParameter = checkableArguments[assertedParameterIndex]; | |
traverseNode(assertedParameter, true); | |
const assertedParameter = getAssertedParameter(checkableArguments, node); | |
if (assertedParameter) { | |
traverseNode(assertedParameter, 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.
[Testing] Some more test cases I think would be good to have:
- Combining
this:
and function overloads - Three very different overloads
...
params, including in combination with the other two things
PR Checklist
Overview
Query for call expressions, check if the function being called is an assertion function, and line up the asserted parameter with the arguments that we see.