You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+60
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,39 @@ Then configure the rules you want to use within `rules` property of your `.eslin
70
70
}
71
71
```
72
72
73
+
### Run the plugin only against test files
74
+
75
+
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:
76
+
77
+
#### ESLint `overrides`
78
+
79
+
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).
80
+
81
+
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:
82
+
83
+
```json
84
+
// .eslintrc
85
+
{
86
+
// 1) Here we have our usual config which applies to the whole project, so we don't put testing-library preset here.
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.
105
+
73
106
## Shareable configurations
74
107
75
108
This plugin exports several recommended configurations that enforce good practices for specific Testing Library packages.
@@ -191,6 +224,12 @@ To enable this configuration use the `extends` property in your
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).
230
+
231
+
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.
232
+
194
233
## Shared Settings
195
234
196
235
There are some configuration options available that will be shared across all the plugin rules. This is achieved using [ESLint Shared Settings](https://eslint.org/docs/user-guide/configuring/configuration-files#adding-shared-settings). These Shared Settings are meant to be used if you need to restrict the Aggressive Reporting mechanism, which is an out of the box advanced feature to lint Testing Library usages in a simpler way for most of the users. **So please before configuring any of these settings**, read more about [the advantages of `eslint-plugin-testing-library` Aggressive Reporting mechanism](docs/migrating-to-v4-guide.md#aggressive-reporting), and [how it's affected by these settings](docs/migrating-to-v4-guide.md#shared-settings).
@@ -227,6 +266,27 @@ A list of function names that are valid as Testing Library custom renders. Relat
227
266
228
267
[You can find more details here](docs/migrating-to-v4-guide.md#testing-librarycustom-renders).
229
268
269
+
## Troubleshooting
270
+
271
+
### There are errors reported in non-testing files
272
+
273
+
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).
274
+
275
+
You can avoid this by:
276
+
277
+
1.[running `eslint-plugin-testing-library` only against testing files](#run-the-plugin-only-against-test-files)
278
+
2.[limiting the scope of Aggressive Reporting through Shared Settings](#shared-settings)
279
+
280
+
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.
281
+
282
+
### There are false positives in testing files
283
+
284
+
If you are getting false positive ESLint errors in your testing files, this could be caused by [Aggressive Reporting](#aggressive-reporting).
285
+
286
+
You can avoid this by [limiting the scope of Aggressive Reporting through Shared Settings](#shared-settings)
287
+
288
+
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.
289
+
230
290
## Contributors ✨
231
291
232
292
Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/docs/en/emoji-key)):
0 commit comments