-
Notifications
You must be signed in to change notification settings - Fork 148
fix: guard against null identifier nodes #309
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
branches: 90, | ||
functions: 90, | ||
lines: 90, |
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've dropped the coverage threshold a bit since I prefer to guard against null nodes everywhere even if there is no possible code for it. We'll see what I do with this after releasing v4.
@@ -83,13 +89,22 @@ export default createTestingLibraryRule<Options, MessageIds>({ | |||
}, | |||
CallExpression(node) { | |||
const callExpressionIdentifier = getDeepestIdentifierNode(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.
@timdeschryver This is really weird: getDeepestIdentifierNode
(and some other utils for finding identifiers) are typed as returning TSESTree.Identifier | null
. However, TS is assuming they always returning TSESTree.Identifier
but never null
:
Then, if I update the function to return ''
instead of return null
and update the returned type to TSESTree.Identifier | string
, TS starts complaining about returned value saved in all these rules might not be an Identifier
. Is this a bug on TS? Am I missing something else? I don't get why it always assumes null
won't be returned.
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 suspect turning on strictNullChecks in the tsconfig would fix that.
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.
Oh wow... TIL...
@epmatsw is right, you'll have to turn the strict mode on.
I would encourage to turn on strict mode though, not just strict null checks.
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.
Aah damn! I thought we had strict
enabled, but anyway I didn't expect those nullable values to be silent. I'm gonna enable strict mode and fix all corresponding issues then. Thanks guys.
@@ -139,6 +139,10 @@ ruleTester.run(RULE_NAME, rule, { | |||
debug() | |||
`, | |||
}, | |||
|
|||
`// cover edge case for https://github.com/testing-library/eslint-plugin-testing-library/issues/306 | |||
thing.method.lastCall.args[0](); |
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.
Test for issue mentioned by @epmatsw
Ok, so I've enabled TS |
Hmm. Maybe throw an |
That fixed almost all of them. The problem is the Now I got some tests failing, I'm looking into them. |
Everything ok now, merging to test it on beta 3. |
π This PR is included in version 4.0.0-beta.3 π The release is available on: Your semantic-release bot π¦π |
π This PR is included in version 4.0.0 π The release is available on: Your semantic-release bot π¦π |
Closes #305. Closes #306.