Socket
Socket
Sign inDemoInstall

eslint-plugin-testing-library

Package Overview
Dependencies
Maintainers
3
Versions
155
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.1 to 4.0.2

node-utils/index.js

4

detect-testing-library-utils.js

@@ -81,2 +81,5 @@ "use strict";

};
const isBuiltInQuery = (node) => {
return utils_1.ALL_QUERIES_COMBINATIONS.includes(node.name);
};
const isAsyncUtil = (node, validNames = utils_1.ASYNC_UTILS) => {

@@ -314,2 +317,3 @@ return isTestingLibraryUtil(node, (identifierNodeName, originalNodeName) => {

isCustomQuery,
isBuiltInQuery,
isAsyncUtil,

@@ -316,0 +320,0 @@ isFireEventUtil,

2

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

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

@@ -73,2 +73,35 @@ <div align="center">

### Run the plugin only against test files
With the default setup mentioned before, `eslint-plugin-testing-library` will be run against your whole codebase. If you want to run this plugin only against your tests files, you have the following options:
#### ESLint `overrides`
One way of restricting ESLint config by file patterns is by using [ESLint `overrides`](https://eslint.org/docs/user-guide/configuring/configuration-files#configuration-based-on-glob-patterns).
Assuming you are using the same pattern for your test files as [Jest by default](https://jestjs.io/docs/configuration#testmatch-arraystring), the following config would run `eslint-plugin-testing-library` only against your test files:
```javascript
// .eslintrc
{
// 1) Here we have our usual config which applies to the whole project, so we don't put testing-library preset here.
"extends": ["airbnb", "plugin:prettier/recommended"],
// 2) We load eslint-plugin-testing-library globally with other ESLint plugins.
"plugins": ["react-hooks", "testing-library"],
"overrides": [
{
// 3) Now we enable eslint-plugin-testing-library rules or preset only for matching files!
"files": ["**/__tests__/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[jt]s?(x)"],
"extends": ["plugin:testing-library/react"]
},
],
};
```
#### ESLint Cascading and Hierachy
Another approach for customizing ESLint config by paths is through [ESLint Cascading and Hierachy](https://eslint.org/docs/user-guide/configuring/configuration-files#cascading-and-hierarchy). This is useful if all your tests are placed under the same folder, so you can place there another `.eslintrc` where you enable `eslint-plugin-testing-library` for applying it only to the files under such folder, rather than enabling it on your global `.eslintrc` which would apply to your whole project.
## Shareable configurations

@@ -195,2 +228,8 @@

## Aggressive Reporting
In v4 this plugin introduced a new feature called "Aggressive Reporting", which intends to detect Testing Library utils usages even if they don't come directly from a Testing Library package (i.e. [using a custom utility file to re-export everything from Testing Library](https://testing-library.com/docs/react-testing-library/setup/#custom-render)). You can [read more about this feature here](docs/migrating-to-v4-guide.md#aggressive-reporting).
If you are looking to restricting this feature, please refer to the [Shared Settings section](#shared-settings) to do so. It's not possible to switch this mechanism entirely off yet, but there will be a new option in the Shared Settings in the future to be able to achieve this.
## Shared Settings

@@ -232,2 +271,23 @@

## Troubleshooting
### There are errors reported in non-testing files
If you find ESLint errors related to `eslint-plugin-testing-library` in files other than testing, this could be caused by [Aggressive Reporting](#aggressive-reporting).
You can avoid this by:
1. [running `eslint-plugin-testing-library` only against testing files](#run-the-plugin-only-against-test-files)
2. [limiting the scope of Aggressive Reporting through Shared Settings](#shared-settings)
If you think the error you are getting is not related to this at all, please [fill a new issue](https://github.com/testing-library/eslint-plugin-testing-library/issues/new/choose) with as many details as possible.
### There are false positives in testing files
If you are getting false positive ESLint errors in your testing files, this could be caused by [Aggressive Reporting](#aggressive-reporting).
You can avoid this by [limiting the scope of Aggressive Reporting through Shared Settings](#shared-settings)
If you think the error you are getting is not related to this at all, please [fill a new issue](https://github.com/testing-library/eslint-plugin-testing-library/issues/new/choose) with as many details as possible.
## Contributors ✨

@@ -234,0 +294,0 @@

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

experimental_utils_1.ASTUtils.isIdentifier(property.key) &&
helpers.isQuery(property.key)) {
helpers.isBuiltInQuery(property.key)) {
safeDestructuredQueries.push(property.key.name);

@@ -82,3 +82,3 @@ }

'CallExpression > Identifier'(node) {
if (!helpers.isQuery(node)) {
if (!helpers.isBuiltInQuery(node)) {
return;

@@ -94,3 +94,3 @@ }

}
if (!helpers.isQuery(node)) {
if (!helpers.isBuiltInQuery(node)) {
return;

@@ -97,0 +97,0 @@ }

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