-
Notifications
You must be signed in to change notification settings - Fork 150
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
Changes from 3 commits
c176c2a
83f27d8
91abe97
abfe5e8
751889b
8ceb80f
c20dbb9
cc040a5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,6 +48,10 @@ export default createTestingLibraryRule<Options, MessageIds>({ | |
VariableDeclarator(node) { | ||
const initIdentifierNode = getDeepestIdentifierNode(node.init); | ||
|
||
if (!initIdentifierNode) { | ||
return; | ||
} | ||
|
||
const isRenderWrapperVariableDeclarator = initIdentifierNode | ||
? renderWrapperNames.includes(initIdentifierNode.name) | ||
: false; | ||
|
@@ -68,9 +72,11 @@ export default createTestingLibraryRule<Options, MessageIds>({ | |
ASTUtils.isIdentifier(property.key) && | ||
property.key.name === 'debug' | ||
) { | ||
suspiciousDebugVariableNames.push( | ||
getDeepestIdentifierNode(property.value).name | ||
); | ||
const identifierNode = getDeepestIdentifierNode(property.value); | ||
|
||
if (identifierNode) { | ||
suspiciousDebugVariableNames.push(identifierNode.name); | ||
} | ||
} | ||
} | ||
} | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. @timdeschryver This is really weird: Then, if I update the function to There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. Oh wow... TIL... There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Aah damn! I thought we had |
||
|
||
if (!callExpressionIdentifier) { | ||
return; | ||
} | ||
|
||
if (helpers.isRenderUtil(callExpressionIdentifier)) { | ||
detectRenderWrapper(callExpressionIdentifier); | ||
} | ||
|
||
const referenceNode = getReferenceNode(node); | ||
const referenceIdentifier = getPropertyIdentifierNode(referenceNode); | ||
|
||
if (!referenceIdentifier) { | ||
return; | ||
} | ||
|
||
const isDebugUtil = helpers.isDebugUtil(callExpressionIdentifier); | ||
const isDeclaredDebugVariable = suspiciousDebugVariableNames.includes( | ||
callExpressionIdentifier.name | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Test for issue mentioned by @epmatsw |
||
`, | ||
], | ||
|
||
invalid: [ | ||
|
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.