Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

eslint-plugin-testing-library

Package Overview
Dependencies
Maintainers
3
Versions
164
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

eslint-plugin-testing-library - npm Package Compare versions

Comparing version 4.0.0-beta.1 to 4.0.0-beta.2

15

detect-testing-library-utils.js

@@ -89,5 +89,14 @@ "use strict";

const isUserEventUtil = (node) => {
return isTestingLibraryUtil(node, (identifierNodeName, originalNodeName) => {
return [identifierNodeName, originalNodeName].includes('userEvent');
});
const userEvent = findImportedUserEventSpecifier();
let userEventName;
if (userEvent) {
userEventName = userEvent.name;
}
else if (isAggressiveModuleReportingEnabled()) {
userEventName = USER_EVENT_NAME;
}
if (!userEventName) {
return false;
}
return node.name === userEventName;
};

@@ -94,0 +103,0 @@ const isFireEventMethod = (node) => {

10

node-utils.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hasImportMatch = exports.getInnermostReturningFunction = exports.hasClosestExpectResolvesRejects = exports.getAssertNodeInfo = exports.getImportModuleName = exports.getFunctionName = exports.getReferenceNode = exports.getDeepestIdentifierNode = exports.getPropertyIdentifierNode = exports.getFunctionReturnStatementNode = exports.getInnermostFunctionScope = exports.getVariableReferences = exports.isPromiseHandled = exports.isPromisesArrayResolved = exports.isPromiseAllSettled = exports.isPromiseAll = exports.isPromiseIdentifier = exports.hasChainedThen = exports.isImportDeclaration = exports.isArrayExpression = exports.isReturnStatement = exports.isArrowFunctionExpression = exports.hasThenProperty = exports.isObjectExpression = exports.isCallExpressionCallee = exports.findClosestCallNode = exports.findClosestCallExpressionNode = exports.isExpressionStatement = exports.isJSXAttribute = exports.isProperty = exports.isObjectPattern = exports.isBlockStatement = exports.isImportDefaultSpecifier = exports.isImportNamespaceSpecifier = exports.isImportSpecifier = exports.isLiteral = exports.isMemberExpression = exports.isNewExpression = exports.isCallExpression = void 0;
exports.hasImportMatch = exports.getInnermostReturningFunction = exports.hasClosestExpectResolvesRejects = exports.getAssertNodeInfo = exports.getImportModuleName = exports.getFunctionName = exports.getReferenceNode = exports.getDeepestIdentifierNode = exports.getPropertyIdentifierNode = exports.getFunctionReturnStatementNode = exports.getInnermostFunctionScope = exports.getVariableReferences = exports.isPromiseHandled = exports.isPromisesArrayResolved = exports.isPromiseAllSettled = exports.isPromiseAll = exports.isPromiseIdentifier = exports.hasChainedThen = exports.isImportDeclaration = exports.isArrayExpression = exports.isReturnStatement = exports.isArrowFunctionExpression = exports.hasThenProperty = exports.isObjectExpression = exports.findClosestCallNode = exports.findClosestCallExpressionNode = exports.isExpressionStatement = exports.isJSXAttribute = exports.isProperty = exports.isObjectPattern = exports.isBlockStatement = exports.isImportDefaultSpecifier = exports.isImportNamespaceSpecifier = exports.isImportSpecifier = exports.isLiteral = exports.isMemberExpression = exports.isNewExpression = exports.isCallExpression = void 0;
const experimental_utils_1 = require("@typescript-eslint/experimental-utils");

@@ -108,10 +108,2 @@ const ValidLeftHandSideExpressions = [

exports.findClosestCallNode = findClosestCallNode;
function isCallExpressionCallee(node, identifier) {
const nodeInnerIdentifier = getDeepestIdentifierNode(node);
if (nodeInnerIdentifier) {
return nodeInnerIdentifier.name === identifier.name;
}
return false;
}
exports.isCallExpressionCallee = isCallExpressionCallee;
function isObjectExpression(node) {

@@ -118,0 +110,0 @@ return (node === null || node === void 0 ? void 0 : node.type) === experimental_utils_1.AST_NODE_TYPES.ObjectExpression;

{
"name": "eslint-plugin-testing-library",
"version": "4.0.0-beta.1",
"version": "4.0.0-beta.2",
"description": "ESLint rules for Testing Library",

@@ -5,0 +5,0 @@ "keywords": [

@@ -60,3 +60,3 @@ "use strict";

data: {
name: referenceNode.name,
name: node.name,
},

@@ -63,0 +63,0 @@ });

@@ -25,16 +25,13 @@ "use strict";

return {
'AwaitExpression > CallExpression Identifier'(node) {
const closestCallExpression = node_utils_1.findClosestCallExpressionNode(node, true);
if (!closestCallExpression) {
'AwaitExpression > CallExpression'(node) {
const deepestIdentifierNode = node_utils_1.getDeepestIdentifierNode(node);
if (!deepestIdentifierNode) {
return;
}
if (!node_utils_1.isCallExpressionCallee(closestCallExpression, node)) {
return;
}
if (helpers.isSyncQuery(node)) {
if (helpers.isSyncQuery(deepestIdentifierNode)) {
context.report({
node,
node: deepestIdentifierNode,
messageId: 'noAwaitSyncQuery',
data: {
name: node.name,
name: deepestIdentifierNode.name,
},

@@ -41,0 +38,0 @@ });

@@ -24,4 +24,7 @@ "use strict";

create: function (context, _, helpers) {
function totalExpect(body) {
function getExpectNodes(body) {
return body.filter((node) => {
if (!node_utils_1.isExpressionStatement(node)) {
return false;
}
const expressionIdentifier = node_utils_1.getPropertyIdentifierNode(node);

@@ -40,9 +43,14 @@ if (!expressionIdentifier) {

}
if (totalExpect(node.body).length <= 1) {
const expectNodes = getExpectNodes(node.body);
if (expectNodes.length <= 1) {
return;
}
context.report({
node: callExpressionNode,
messageId: 'noWaitForMultipleAssertion',
});
for (let i = 0; i < expectNodes.length; i++) {
if (i !== 0) {
context.report({
node: expectNodes[i],
messageId: 'noWaitForMultipleAssertion',
});
}
}
}

@@ -49,0 +57,0 @@ return {

@@ -24,4 +24,7 @@ "use strict";

create: function (context, _, helpers) {
function hasSideEffects(body) {
return body.some((node) => {
function getSideEffectNodes(body) {
return body.filter((node) => {
if (!node_utils_1.isExpressionStatement(node)) {
return false;
}
const expressionIdentifier = node_utils_1.getPropertyIdentifierNode(node);

@@ -41,9 +44,12 @@ if (!expressionIdentifier) {

}
if (!hasSideEffects(node.body)) {
const sideEffectNodes = getSideEffectNodes(node.body);
if (sideEffectNodes.length === 0) {
return;
}
context.report({
node: callExpressionNode,
messageId: 'noSideEffectsWaitFor',
});
for (const sideEffectNode of sideEffectNodes) {
context.report({
node: sideEffectNode,
messageId: 'noSideEffectsWaitFor',
});
}
}

@@ -50,0 +56,0 @@ return {

@@ -31,3 +31,3 @@ "use strict";

docs: {
description: 'Suggest using find* instead of waitFor to wait for elements',
description: 'Suggest using `find*` query instead of `waitFor` + `get*` to wait for elements',
category: 'Best Practices',

@@ -37,3 +37,3 @@ recommended: 'warn',

messages: {
preferFindBy: 'Prefer {{queryVariant}}{{queryMethod}} method over using await {{fullQuery}}',
preferFindBy: 'Prefer `{{queryVariant}}{{queryMethod}}` query over using `{{waitForMethodName}}` + `{{prevQuery}}`',
},

@@ -46,3 +46,4 @@ fixable: 'code',

const sourceCode = context.getSourceCode();
function reportInvalidUsage(node, { queryVariant, queryMethod, fix, }) {
function reportInvalidUsage(node, replacementParams) {
const { queryMethod, queryVariant, prevQuery, waitForMethodName, fix, } = replacementParams;
context.report({

@@ -54,3 +55,4 @@ node,

queryMethod,
fullQuery: sourceCode.getText(node),
prevQuery,
waitForMethodName,
},

@@ -63,3 +65,3 @@ fix,

if (!experimental_utils_1.ASTUtils.isIdentifier(node.callee) ||
!exports.WAIT_METHODS.includes(node.callee.name)) {
!helpers.isAsyncUtil(node.callee, exports.WAIT_METHODS)) {
return;

@@ -74,2 +76,3 @@ }

}
const waitForMethodName = node.callee.name;
if (node_utils_1.isMemberExpression(argument.body.callee) &&

@@ -87,2 +90,4 @@ experimental_utils_1.ASTUtils.isIdentifier(argument.body.callee.property) &&

queryVariant,
prevQuery: fullQueryMethod,
waitForMethodName,
fix(fixer) {

@@ -113,2 +118,4 @@ const property = argument.body

queryVariant,
prevQuery: fullQueryMethod,
waitForMethodName,
fix(fixer) {

@@ -115,0 +122,0 @@ if (helpers.isCustomQuery(argument.body

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc