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 3.3.1 to 3.3.2

2

package.json
{
"name": "eslint-plugin-testing-library",
"version": "3.3.1",
"version": "3.3.2",
"description": "ESLint rules for Testing Library",

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

@@ -26,3 +26,3 @@ <div align="center">

<!-- ALL-CONTRIBUTORS-BADGE:START - Do not remove or modify this section -->
[![All Contributors](https://img.shields.io/badge/all_contributors-25-orange.svg?style=flat-square)](#contributors-)
[![All Contributors](https://img.shields.io/badge/all_contributors-28-orange.svg?style=flat-square)](#contributors-)
<!-- ALL-CONTRIBUTORS-BADGE:END -->

@@ -211,3 +211,6 @@

<td align="center"><a href="https://github.com/jrparish"><img src="https://avatars3.githubusercontent.com/u/5173987?v=4" width="100px;" alt=""/><br /><sub><b>Jacob Parish</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-testing-library/issues?q=author%3Ajrparish" title="Bug reports">🐛</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=jrparish" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=jrparish" title="Tests">⚠️</a></td>
<td align="center"><a href="https://nickmccurdy.com/"><img src="https://avatars0.githubusercontent.com/u/927220?v=4" width="100px;" alt=""/><br /><sub><b>Nick McCurdy</b></sub></a><br /><a href="#ideas-nickmccurdy" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=nickmccurdy" title="Code">💻</a></td>
<td align="center"><a href="https://nickmccurdy.com/"><img src="https://avatars0.githubusercontent.com/u/927220?v=4" width="100px;" alt=""/><br /><sub><b>Nick McCurdy</b></sub></a><br /><a href="#ideas-nickmccurdy" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=nickmccurdy" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/pulls?q=is%3Apr+reviewed-by%3Anickmccurdy" title="Reviewed Pull Requests">👀</a></td>
<td align="center"><a href="https://stefancameron.com/"><img src="https://avatars3.githubusercontent.com/u/2855350?v=4" width="100px;" alt=""/><br /><sub><b>Stefan Cameron</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-testing-library/issues?q=author%3Astefcameron" title="Bug reports">🐛</a></td>
<td align="center"><a href="https://www.linkedin.com/in/mateusfelix/"><img src="https://avatars2.githubusercontent.com/u/4968788?v=4" width="100px;" alt=""/><br /><sub><b>Mateus Felix</b></sub></a><br /><a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=thebinaryfelix" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=thebinaryfelix" title="Tests">⚠️</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=thebinaryfelix" title="Documentation">📖</a></td>
<td align="center"><a href="https://github.com/renatoagds"><img src="https://avatars2.githubusercontent.com/u/1663717?v=4" width="100px;" alt=""/><br /><sub><b>Renato Augusto Gama dos Santos</b></sub></a><br /><a href="#ideas-renatoagds" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=renatoagds" title="Code">💻</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=renatoagds" title="Documentation">📖</a> <a href="https://github.com/testing-library/eslint-plugin-testing-library/commits?author=renatoagds" title="Tests">⚠️</a></td>
</tr>

@@ -214,0 +217,0 @@ </table>

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

function reportInvalidUsage(node, _a) {
var queryVariant = _a.queryVariant, queryMethod = _a.queryMethod, callArguments = _a.callArguments, caller = _a.caller;
var queryVariant = _a.queryVariant, queryMethod = _a.queryMethod, fix = _a.fix;
context.report({

@@ -33,6 +33,3 @@ node: node,

data: { queryVariant: queryVariant, queryMethod: queryMethod, fullQuery: sourceCode.getText(node) },
fix: function (fixer) {
var newCode = "" + (caller ? caller + "." : '') + queryVariant + queryMethod + "(" + callArguments.map(function (node) { return sourceCode.getText(node); }).join(', ') + ")";
return fixer.replaceText(node, newCode);
}
fix: fix,
});

@@ -53,9 +50,14 @@ }

if (node_utils_1.isMemberExpression(argument.body.callee) && node_utils_1.isIdentifier(argument.body.callee.property) && node_utils_1.isIdentifier(argument.body.callee.object) && utils_1.SYNC_QUERIES_COMBINATIONS.includes(argument.body.callee.property.name)) {
var queryMethod = argument.body.callee.property.name;
var caller = argument.body.callee.object.name;
var fullQueryMethod = argument.body.callee.property.name;
var caller_1 = argument.body.callee.object.name;
var queryVariant_1 = getFindByQueryVariant(fullQueryMethod);
var callArguments_1 = argument.body.arguments;
var queryMethod_1 = fullQueryMethod.split('By')[1];
reportInvalidUsage(node, {
queryMethod: queryMethod.split('By')[1],
queryVariant: getFindByQueryVariant(queryMethod),
callArguments: argument.body.arguments,
caller: caller,
queryMethod: queryMethod_1,
queryVariant: queryVariant_1,
fix: function (fixer) {
var newCode = caller_1 + "." + queryVariant_1 + queryMethod_1 + "(" + callArguments_1.map(function (node) { return sourceCode.getText(node); }).join(', ') + ")";
return fixer.replaceText(node, newCode);
}
});

@@ -65,7 +67,29 @@ return;

if (node_utils_1.isIdentifier(argument.body.callee) && utils_1.SYNC_QUERIES_COMBINATIONS.includes(argument.body.callee.name)) {
var queryMethod = argument.body.callee.name;
var fullQueryMethod_1 = argument.body.callee.name;
var queryMethod_2 = fullQueryMethod_1.split('By')[1];
var queryVariant_2 = getFindByQueryVariant(fullQueryMethod_1);
var callArguments_2 = argument.body.arguments;
reportInvalidUsage(node, {
queryMethod: queryMethod.split('By')[1],
queryVariant: getFindByQueryVariant(queryMethod),
callArguments: argument.body.arguments,
queryMethod: queryMethod_2,
queryVariant: queryVariant_2,
fix: function (fixer) {
var findByMethod = "" + queryVariant_2 + queryMethod_2;
var allFixes = [];
var newCode = findByMethod + "(" + callArguments_2.map(function (node) { return sourceCode.getText(node); }).join(', ') + ")";
allFixes.push(fixer.replaceText(node, newCode));
var definition = findRenderDefinitionDeclaration(context.getScope(), fullQueryMethod_1);
if (!definition) {
return allFixes;
}
if (node_utils_1.isObjectPattern(definition.parent.parent)) {
var allVariableDeclarations = definition.parent.parent;
if (allVariableDeclarations.properties.some(function (p) { return node_utils_1.isProperty(p) && node_utils_1.isIdentifier(p.key) && p.key.name === findByMethod; })) {
return allFixes;
}
var textDestructuring = sourceCode.getText(allVariableDeclarations);
var text = textDestructuring.substring(0, textDestructuring.length - 2) + (", " + findByMethod + " }");
allFixes.push(fixer.replaceText(allVariableDeclarations, text));
}
return allFixes;
}
});

@@ -81,1 +105,16 @@ return;

}
exports.getFindByQueryVariant = getFindByQueryVariant;
function findRenderDefinitionDeclaration(scope, query) {
if (!scope) {
return null;
}
var variable = scope.variables.find(function (v) { return v.name === query; });
if (variable) {
var def = variable.defs.find(function (_a) {
var name = _a.name;
return name.name === query;
});
return def.name;
}
return findRenderDefinitionDeclaration(scope.upper, query);
}
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