From 9cbe4d8ed044f1f21a82c7c6906df2f76e99a258 Mon Sep 17 00:00:00 2001 From: Retsam Date: Mon, 19 Aug 2019 16:20:40 -0400 Subject: [PATCH] test(eslint-plugin): add tests for generic type params --- .../tests/rules/no-unnecessary-condition.test.ts | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts index 842e5b715a9..75cb093e2dc 100644 --- a/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts +++ b/packages/eslint-plugin/tests/rules/no-unnecessary-condition.test.ts @@ -54,6 +54,12 @@ const t1 = (b1 && b2) ? 'yes' : 'no'`, necessaryConditionTest('any'), // any necessaryConditionTest('unknown'), // unknown + // Generic type params + ` +function test(t: T) { + return t ? 'yes' : 'no' +}`, + // Supports ignoring the RHS { code: ` @@ -94,6 +100,15 @@ const t1 = (b1 && b2) ? 'yes' : 'no'`, unnecessaryConditionTest('void', 'alwaysFalsy'), unnecessaryConditionTest('never', 'never'), + // Generic type params + { + code: ` +function test(t: T) { + return t ? 'yes' : 'no' +}`, + errors: [ruleError(3, 10, 'alwaysTruthy')], + }, + // Still errors on in the expected locations when ignoring RHS { options: [{ ignoreRhs: true }],