Skip to content

Commit

Permalink
fix(no-debug): support async render (#79)
Browse files Browse the repository at this point in the history
* fix: support async render

* fix: address PR feedback
  • Loading branch information
Thomas Lombart committed Feb 4, 2020
1 parent 572a289 commit caeebb4
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 7 deletions.
29 changes: 22 additions & 7 deletions lib/rules/no-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,7 @@ module.exports = {

return {
VariableDeclarator(node) {
if (
node.init &&
node.init.callee &&
['render', ...renderFunctions].some(
name => name === node.init.callee.name
)
) {
if (isRenderVariableDeclarator(node, renderFunctions)) {
if (
node.id.type === 'ObjectPattern' &&
node.id.properties.some(property => property.key.name === 'debug')
Expand Down Expand Up @@ -149,3 +143,24 @@ module.exports = {
};
},
};

function isRenderFunction(callNode, renderFunctions) {
return ['render', ...renderFunctions].some(
name => name === callNode.callee.name
);
}

function isRenderVariableDeclarator(node, renderFunctions) {
if (node.init) {
if (node.init.type === 'AwaitExpression') {
return (
node.init.argument &&
isRenderFunction(node.init.argument, renderFunctions)
);
} else {
return node.init.callee && isRenderFunction(node.init, renderFunctions);
}
}

return false;
}
28 changes: 28 additions & 0 deletions tests/lib/rules/no-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ ruleTester.run('no-debug', rule, {
},
],
},
{
code: `
describe(() => {
test(async () => {
const { debug } = await render("foo")
debug()
})
})`,
errors: [
{
messageId: 'noDebug',
},
],
},
{
code: `
describe(() => {
test(async () => {
const utils = await render("foo")
utils.debug()
})
})`,
errors: [
{
messageId: 'noDebug',
},
],
},
{
code: `
const { screen } = require('@testing-library/dom')
Expand Down

0 comments on commit caeebb4

Please sign in to comment.