From 70ad558d7dbd1b436a4102ca9feb2ba873f47853 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Wed, 20 Apr 2022 19:12:43 +1200 Subject: [PATCH] docs: add section about using overrides to apply rules to just test-related files (#1080) --- README.md | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/README.md b/README.md index 44abff693..67554f135 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,34 @@ doing: This is included in all configs shared by this plugin, so can be omitted if extending them. +### Running rules only on test-related files + +The rules provided by this plugin assume that the files they are checking are +test-related. This means it's generally not suitable to include them in your +top-level configuration as that applies to all files being linted which can +include source files. + +You can use +[overrides](https://eslint.org/docs/user-guide/configuring/configuration-files#how-do-overrides-work) +to have ESLint apply additional rules to specific files: + +```json +{ + "extends": ["eslint:recommended"], + "overrides": [ + { + "files": ["test/**"], + "plugins": ["jest"], + "extends": ["plugin:jest/recommended"], + "rules": { "jest/prefer-expect-assertions": "off" } + } + ], + "rules": { + "indent": ["error", 2] + } +} +``` + ### Jest `version` setting The behaviour of some rules (specifically [`no-deprecated-functions`][]) change