From 783ced0c57613ff75a9232aa3efb45927f798d73 Mon Sep 17 00:00:00 2001 From: Tim Deschryver <28659384+timdeschryver@users.noreply.github.com> Date: Thu, 18 Jun 2020 10:13:07 +0200 Subject: [PATCH] fix(no-debug): catch all screen imports (#175) Closes #174 --- lib/rules/no-debug.ts | 12 ++++++------ tests/lib/rules/no-debug.test.ts | 12 ++++++++++++ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/rules/no-debug.ts b/lib/rules/no-debug.ts index 588b997a..22bbdc58 100644 --- a/lib/rules/no-debug.ts +++ b/lib/rules/no-debug.ts @@ -8,6 +8,7 @@ import { isLiteral, isAwaitExpression, isMemberExpression, + isImportSpecifier, } from '../node-utils'; export const RULE_NAME = 'no-debug'; @@ -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'; diff --git a/tests/lib/rules/no-debug.test.ts b/tests/lib/rules/no-debug.test.ts index 17387352..ad175bac 100644 --- a/tests/lib/rules/no-debug.test.ts +++ b/tests/lib/rules/no-debug.test.ts @@ -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';