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
2
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 1.3.3 to 1.3.4

64

lib/rules/prefer-explicit-assert.js
'use strict';
const { findParent, getDocsUrl, ALL_QUERIES_METHODS } = require('../utils');
const { getDocsUrl, ALL_QUERIES_METHODS } = require('../utils');

@@ -9,26 +9,8 @@ const ALL_GET_BY_QUERIES = ALL_QUERIES_METHODS.map(

const findCallExpressionParent = node =>
findParent(node, node => node.type === 'CallExpression');
const isValidQuery = (node, customQueryNames = []) =>
const isValidQuery = (node, customQueryNames) =>
ALL_GET_BY_QUERIES.includes(node.name) ||
customQueryNames.includes(node.name);
const isDirectlyCalledByFunction = node =>
node.parent.type === 'CallExpression';
const isAtTopLevel = node => node.parent.parent.type === 'ExpressionStatement';
const isReturnedByArrowFunctionExpression = node =>
node.parent.type === 'ArrowFunctionExpression';
const isDeclared = node =>
!!findParent(node, node => node.type === 'VariableDeclarator');
const isReturnedByReturnStatement = node =>
node.parent.type === 'ReturnStatement';
const isInDestructuringStatement = node =>
(node.parent.type === 'Property' &&
node.parent.parent.type === 'ObjectPattern') ||
node.parent.type === 'ArrayPattern';
module.exports = {

@@ -62,24 +44,28 @@ meta: {

create: function(context) {
const getQueryCalls = [];
const customQueryNames =
(context.options && context.options.length > 0
? context.options[0].customQueryNames
: []) || [];
return {
'CallExpression Identifier'(node) {
const callExpressionNode = findCallExpressionParent(node);
let customQueryNames;
if (context.options && context.options.length > 0) {
[{ customQueryNames }] = context.options;
if (isValidQuery(node, customQueryNames)) {
getQueryCalls.push(node);
}
},
'Program:exit'() {
getQueryCalls.forEach(queryCall => {
const node =
queryCall.parent.type === 'MemberExpression'
? queryCall.parent
: queryCall;
if (
isValidQuery(node, customQueryNames) &&
!isInDestructuringStatement(node) &&
!isDirectlyCalledByFunction(callExpressionNode) &&
!isReturnedByArrowFunctionExpression(callExpressionNode) &&
!isDeclared(callExpressionNode) &&
!isReturnedByReturnStatement(callExpressionNode)
) {
context.report({
node,
messageId: 'preferExplicitAssert',
});
}
if (isAtTopLevel(node)) {
context.report({
node: queryCall,
messageId: 'preferExplicitAssert',
});
}
});
},

@@ -86,0 +72,0 @@ };

@@ -51,14 +51,3 @@ 'use strict';

const findParent = (node, cb) => {
if (cb(node)) {
return node;
} else if (node.parent) {
return findParent(node.parent, cb);
}
return null;
};
module.exports = {
findParent,
getDocsUrl,

@@ -65,0 +54,0 @@ SYNC_QUERIES_VARIANTS,

{
"name": "eslint-plugin-testing-library",
"version": "1.3.3",
"version": "1.3.4",
"description": "ESLint rules for Testing Library",

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

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