Skip to content

Commit caeebb4

Browse files
fix(no-debug): support async render (#79)
* fix: support async render * fix: address PR feedback
1 parent 572a289 commit caeebb4

File tree

2 files changed

+50
-7
lines changed

2 files changed

+50
-7
lines changed

lib/rules/no-debug.js

Lines changed: 22 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,7 @@ module.exports = {
4848

4949
return {
5050
VariableDeclarator(node) {
51-
if (
52-
node.init &&
53-
node.init.callee &&
54-
['render', ...renderFunctions].some(
55-
name => name === node.init.callee.name
56-
)
57-
) {
51+
if (isRenderVariableDeclarator(node, renderFunctions)) {
5852
if (
5953
node.id.type === 'ObjectPattern' &&
6054
node.id.properties.some(property => property.key.name === 'debug')
@@ -149,3 +143,24 @@ module.exports = {
149143
};
150144
},
151145
};
146+
147+
function isRenderFunction(callNode, renderFunctions) {
148+
return ['render', ...renderFunctions].some(
149+
name => name === callNode.callee.name
150+
);
151+
}
152+
153+
function isRenderVariableDeclarator(node, renderFunctions) {
154+
if (node.init) {
155+
if (node.init.type === 'AwaitExpression') {
156+
return (
157+
node.init.argument &&
158+
isRenderFunction(node.init.argument, renderFunctions)
159+
);
160+
} else {
161+
return node.init.callee && isRenderFunction(node.init, renderFunctions);
162+
}
163+
}
164+
165+
return false;
166+
}

tests/lib/rules/no-debug.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,34 @@ ruleTester.run('no-debug', rule, {
147147
},
148148
],
149149
},
150+
{
151+
code: `
152+
describe(() => {
153+
test(async () => {
154+
const { debug } = await render("foo")
155+
debug()
156+
})
157+
})`,
158+
errors: [
159+
{
160+
messageId: 'noDebug',
161+
},
162+
],
163+
},
164+
{
165+
code: `
166+
describe(() => {
167+
test(async () => {
168+
const utils = await render("foo")
169+
utils.debug()
170+
})
171+
})`,
172+
errors: [
173+
{
174+
messageId: 'noDebug',
175+
},
176+
],
177+
},
150178
{
151179
code: `
152180
const { screen } = require('@testing-library/dom')

0 commit comments

Comments
 (0)