Skip to content

Commit 783ced0

Browse files
fix(no-debug): catch all screen imports (#175)
Closes #174
1 parent c3f9b34 commit 783ced0

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

lib/rules/no-debug.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import {
88
isLiteral,
99
isAwaitExpression,
1010
isMemberExpression,
11+
isImportSpecifier,
1112
} from '../node-utils';
1213

1314
export const RULE_NAME = 'no-debug';
@@ -141,12 +142,11 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
141142
},
142143
// checks if import has shape:
143144
// import { screen } from '@testing-library/dom';
144-
'ImportDeclaration ImportSpecifier'(node: TSESTree.ImportSpecifier) {
145-
const importDeclarationNode = node.parent as TSESTree.ImportDeclaration;
146-
147-
if (!hasTestingLibraryImportModule(importDeclarationNode)) return;
148-
149-
hasImportedScreen = node.imported.name === 'screen';
145+
ImportDeclaration(node: TSESTree.ImportDeclaration) {
146+
if (!hasTestingLibraryImportModule(node)) return;
147+
hasImportedScreen = node.specifiers.some(
148+
s => isImportSpecifier(s) && s.imported.name === 'screen'
149+
);
150150
},
151151
// checks if import has shape:
152152
// import * as dtl from '@testing-library/dom';

tests/lib/rules/no-debug.test.ts

+12
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,18 @@ ruleTester.run(RULE_NAME, rule, {
202202
},
203203
],
204204
},
205+
{
206+
// https://github.com/testing-library/eslint-plugin-testing-library/issues/174
207+
code: `
208+
import { screen, render } from '@testing-library/dom'
209+
screen.debug()
210+
`,
211+
errors: [
212+
{
213+
messageId: 'noDebug',
214+
},
215+
],
216+
},
205217
{
206218
code: `
207219
import * as dtl from '@testing-library/dom';

0 commit comments

Comments
 (0)