From 4cfcf080893fbe89689bd4b283bb2f3ad09b19ff Mon Sep 17 00:00:00 2001 From: Gareth Jones Date: Sun, 26 Jul 2020 19:07:16 +1200 Subject: [PATCH] fix(no-if): report conditionals in call expressions fixes #557 --- src/rules/__tests__/no-if.test.ts | 12 ++++++++++++ src/rules/no-if.ts | 4 +++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/rules/__tests__/no-if.test.ts b/src/rules/__tests__/no-if.test.ts index f80276e2a..e1e6d6ac7 100644 --- a/src/rules/__tests__/no-if.test.ts +++ b/src/rules/__tests__/no-if.test.ts @@ -23,6 +23,18 @@ ruleTester.run('conditional expressions', rule, { }, ], invalid: [ + { + code: `it('foo', () => { + expect(bar ? foo : baz).toBe(boo); + }) + `, + errors: [ + { + data: { condition: 'conditional' }, + messageId: 'conditionalInTest', + }, + ], + }, { code: `it('foo', () => { const foo = bar ? foo : baz; diff --git a/src/rules/no-if.ts b/src/rules/no-if.ts index 57ca6e9b2..ded7101a9 100644 --- a/src/rules/no-if.ts +++ b/src/rules/no-if.ts @@ -73,7 +73,9 @@ export default createRule({ return { CallExpression(node) { - stack.push(isTestCase(node)); + if (isTestCase(node)) { + stack.push(true); + } }, FunctionExpression() { stack.push(false);