From 35f32cc9da8741649766c2e33b8a6bcaa46ac0e7 Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Mon, 7 Feb 2022 10:11:43 +1300 Subject: [PATCH] feat: deprecate `no-if` in favor of `no-conditional-in-test` (#1049) --- README.md | 1 - docs/rules/no-if.md | 5 +++++ src/__tests__/__snapshots__/rules.test.ts.snap | 1 - src/rules/no-if.ts | 2 ++ 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 55834f472..9974a2bd6 100644 --- a/README.md +++ b/README.md @@ -167,7 +167,6 @@ installations requiring long-term consistency. | [no-focused-tests](docs/rules/no-focused-tests.md) | Disallow focused tests | ![recommended][] | ![suggest][] | | [no-hooks](docs/rules/no-hooks.md) | Disallow setup and teardown hooks | | | | [no-identical-title](docs/rules/no-identical-title.md) | Disallow identical titles | ![recommended][] | | -| [no-if](docs/rules/no-if.md) | Disallow conditional logic | | | | [no-interpolation-in-snapshots](docs/rules/no-interpolation-in-snapshots.md) | Disallow string interpolation inside snapshots | ![recommended][] | | | [no-jasmine-globals](docs/rules/no-jasmine-globals.md) | Disallow Jasmine globals | ![recommended][] | ![fixable][] | | [no-jest-import](docs/rules/no-jest-import.md) | Disallow importing Jest | ![recommended][] | | diff --git a/docs/rules/no-if.md b/docs/rules/no-if.md index 88756de46..e44015e0b 100644 --- a/docs/rules/no-if.md +++ b/docs/rules/no-if.md @@ -1,5 +1,10 @@ # Disallow conditional logic (`no-if`) +## Deprecated + +This rule has been deprecated in favor of +[`no-conditional-in-test`](no-conditional-in-test.md). + Conditional logic in tests is usually an indication that a test is attempting to cover too much, and not testing the logic it intends to. Each branch of code executing within an if statement will usually be better served by a test devoted diff --git a/src/__tests__/__snapshots__/rules.test.ts.snap b/src/__tests__/__snapshots__/rules.test.ts.snap index 19305726b..7b70d2fe2 100644 --- a/src/__tests__/__snapshots__/rules.test.ts.snap +++ b/src/__tests__/__snapshots__/rules.test.ts.snap @@ -25,7 +25,6 @@ Object { "jest/no-focused-tests": "error", "jest/no-hooks": "error", "jest/no-identical-title": "error", - "jest/no-if": "error", "jest/no-interpolation-in-snapshots": "error", "jest/no-jasmine-globals": "error", "jest/no-jest-import": "error", diff --git a/src/rules/no-if.ts b/src/rules/no-if.ts index e0205463e..66a706ae1 100644 --- a/src/rules/no-if.ts +++ b/src/rules/no-if.ts @@ -44,6 +44,8 @@ export default createRule({ messages: { conditionalInTest: 'Test should not contain {{ condition }} statements.', }, + deprecated: true, + replacedBy: ['no-conditional-in-test'], schema: [], type: 'suggestion', },