Skip to content

fix(no-debug): catch all screen imports #175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 18, 2020
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