eslint-plugin-testing-library
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -5,2 +5,10 @@ 'use strict'; | ||
const LIBRARY_MODULES_WITH_SCREEN = [ | ||
'@testing-library/dom', | ||
'@testing-library/react', | ||
'@testing-library/preact', | ||
'@testing-library/vue', | ||
'@testing-library/svelte', | ||
]; | ||
module.exports = { | ||
@@ -40,2 +48,4 @@ meta: { | ||
let hasImportedScreen = false; | ||
return { | ||
@@ -62,2 +72,40 @@ VariableDeclarator(node) { | ||
}, | ||
[`VariableDeclarator > CallExpression > Identifier[name="require"]`]( | ||
node | ||
) { | ||
const { arguments: args } = node.parent; | ||
const literalNodeScreenModuleName = args.find(args => | ||
LIBRARY_MODULES_WITH_SCREEN.includes(args.value) | ||
); | ||
if (!literalNodeScreenModuleName) { | ||
return; | ||
} | ||
const declaratorNode = node.parent.parent; | ||
if ( | ||
declaratorNode.id.type === 'ObjectPattern' && | ||
declaratorNode.id.properties.some( | ||
property => property.key.name === 'screen' | ||
) | ||
) { | ||
hasImportedScreen = true; | ||
} | ||
}, | ||
ImportDeclaration(node) { | ||
const screenModuleName = LIBRARY_MODULES_WITH_SCREEN.find( | ||
module => module === node.source.value | ||
); | ||
if ( | ||
screenModuleName && | ||
node.specifiers.some( | ||
specifier => specifier.imported.name === 'screen' | ||
) | ||
) { | ||
hasImportedScreen = true; | ||
} | ||
}, | ||
[`CallExpression > Identifier[name="debug"]`](node) { | ||
@@ -71,2 +119,14 @@ if (hasDestructuredDebugStatement) { | ||
}, | ||
[`CallExpression > MemberExpression > Identifier[name="debug"]`](node) { | ||
if ( | ||
hasImportedScreen && | ||
node.parent && | ||
node.parent.object.name === 'screen' | ||
) { | ||
context.report({ | ||
node, | ||
messageId: 'noDebug', | ||
}); | ||
} | ||
}, | ||
'Program:exit'() { | ||
@@ -73,0 +133,0 @@ renderVariableDeclarators.forEach(renderVar => { |
{ | ||
"name": "eslint-plugin-testing-library", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "ESLint rules for Testing Library", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
44334
921