Skip to content

Commit 648c7b4

Browse files
benmonroBelco90
authored andcommitted
feat(no-debug): option for render function names (#19)
* feat(no-debug): render function names * feat(no-debug): added docs
1 parent 63c4fde commit 648c7b4

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

docs/rules/no-debug.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ const utils = render(<Hello />);
1616
utils.debug();
1717
```
1818

19+
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.
20+
21+
```
22+
"testing-library/no-debug": ["error", {"renderFunctions":["renderWithRedux", "renderWithRouter"]}],
23+
```
24+
1925
## Further Reading
2026

2127
- [debug API in React Testing Library](https://testing-library.com/docs/react-testing-library/api#debug)

lib/rules/no-debug.js

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,35 @@ module.exports = {
1515
noDebug: 'Unexpected debug statement',
1616
},
1717
fixable: null,
18-
schema: [],
18+
schema: [
19+
{
20+
type: 'object',
21+
properties: {
22+
renderFunctions: {
23+
type: 'array',
24+
},
25+
},
26+
},
27+
],
1928
},
2029

2130
create: function(context) {
2231
let hasDestructuredDebugStatement = false;
2332
const renderVariableDeclarators = [];
33+
34+
let renderFunctions = [];
35+
if (context.options && context.options.length > 0) {
36+
[{ renderFunctions }] = context.options;
37+
}
38+
2439
return {
2540
VariableDeclarator(node) {
2641
if (
2742
node.init &&
2843
node.init.callee &&
29-
node.init.callee.name === 'render'
44+
['render', ...renderFunctions].some(
45+
name => name === node.init.callee.name
46+
)
3047
) {
3148
if (
3249
node.id.type === 'ObjectPattern' &&

tests/lib/rules/no-debug.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,22 @@ ruleTester.run('no-debug', rule, {
7070
},
7171
],
7272
},
73+
{
74+
code: `
75+
const { debug } = renderWithRedux(<Component/>)
76+
debug()
77+
`,
78+
options: [
79+
{
80+
renderFunctions: ['renderWithRedux'],
81+
},
82+
],
83+
errors: [
84+
{
85+
messageId: 'noDebug',
86+
},
87+
],
88+
},
7389
{
7490
code: `
7591
const utils = render(<Component/>)

0 commit comments

Comments
 (0)