From 3ccef142fe8a2f0bfbb6e1589b34472a1729d566 Mon Sep 17 00:00:00 2001 From: Ben Monro Date: Tue, 8 Oct 2019 09:20:44 -0700 Subject: [PATCH 1/2] feat(no-debug): render function names --- lib/rules/no-debug.js | 21 +++++++++++++++++++-- tests/lib/rules/no-debug.js | 16 ++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/lib/rules/no-debug.js b/lib/rules/no-debug.js index ef977343..16662a63 100644 --- a/lib/rules/no-debug.js +++ b/lib/rules/no-debug.js @@ -15,18 +15,35 @@ module.exports = { noDebug: 'Unexpected debug statement', }, fixable: null, - schema: [], + schema: [ + { + type: 'object', + properties: { + renderFunctions: { + type: 'array', + }, + }, + }, + ], }, create: function(context) { let hasDestructuredDebugStatement = false; const renderVariableDeclarators = []; + + let renderFunctions = []; + if (context.options && context.options.length > 0) { + [{ renderFunctions }] = context.options; + } + return { VariableDeclarator(node) { if ( node.init && node.init.callee && - node.init.callee.name === 'render' + ['render', ...renderFunctions].some( + name => name === node.init.callee.name + ) ) { if ( node.id.type === 'ObjectPattern' && diff --git a/tests/lib/rules/no-debug.js b/tests/lib/rules/no-debug.js index 64413b22..16b87a93 100644 --- a/tests/lib/rules/no-debug.js +++ b/tests/lib/rules/no-debug.js @@ -70,6 +70,22 @@ ruleTester.run('no-debug', rule, { }, ], }, + { + code: ` + const { debug } = renderWithRedux() + debug() + `, + options: [ + { + renderFunctions: ['renderWithRedux'], + }, + ], + errors: [ + { + messageId: 'noDebug', + }, + ], + }, { code: ` const utils = render() From 21edf37fc3ea59f7000dc0cab6d0065f936450b1 Mon Sep 17 00:00:00 2001 From: Ben Monro Date: Tue, 8 Oct 2019 09:34:39 -0700 Subject: [PATCH 2/2] feat(no-debug): added docs --- docs/rules/no-debug.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/docs/rules/no-debug.md b/docs/rules/no-debug.md index bc0cba73..ae51cfc2 100644 --- a/docs/rules/no-debug.md +++ b/docs/rules/no-debug.md @@ -16,6 +16,12 @@ const utils = render(); utils.debug(); ``` +If you use [custom render functions](https://testing-library.com/docs/example-react-redux) then you can set a config option in your `.eslintrc` to look for these. + +``` + "testing-library/no-debug": ["error", {"renderFunctions":["renderWithRedux", "renderWithRouter"]}], +``` + ## Further Reading - [debug API in React Testing Library](https://testing-library.com/docs/react-testing-library/api#debug)