Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions lib/rules/no-debug.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
isLiteral,
isAwaitExpression,
isMemberExpression,
isImportSpecifier,
} from '../node-utils';

export const RULE_NAME = 'no-debug';
Expand Down Expand Up @@ -141,12 +142,11 @@ export default ESLintUtils.RuleCreator(getDocsUrl)({
},
// checks if import has shape:
// import { screen } from '@testing-library/dom';
'ImportDeclaration ImportSpecifier'(node: TSESTree.ImportSpecifier) {
const importDeclarationNode = node.parent as TSESTree.ImportDeclaration;

if (!hasTestingLibraryImportModule(importDeclarationNode)) return;

hasImportedScreen = node.imported.name === 'screen';
ImportDeclaration(node: TSESTree.ImportDeclaration) {
if (!hasTestingLibraryImportModule(node)) return;
hasImportedScreen = node.specifiers.some(
s => isImportSpecifier(s) && s.imported.name === 'screen'
);
},
// checks if import has shape:
// import * as dtl from '@testing-library/dom';
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/no-debug.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,18 @@ ruleTester.run(RULE_NAME, rule, {
},
],
},
{
// https://github.com/testing-library/eslint-plugin-testing-library/issues/174
code: `
import { screen, render } from '@testing-library/dom'
screen.debug()
`,
errors: [
{
messageId: 'noDebug',
},
],
},
{
code: `
import * as dtl from '@testing-library/dom';
Expand Down