From 49240423daef1cdba1e22d47136de2c693bfcafe Mon Sep 17 00:00:00 2001 From: Flo Edelmann Date: Tue, 18 Jul 2023 11:58:39 +0200 Subject: [PATCH] fix: ignore SpreadExpressions in no-only-tests and prefer-output-null --- lib/rules/no-only-tests.js | 1 + lib/rules/prefer-output-null.js | 4 +++- tests/lib/rules/no-only-tests.js | 3 ++- tests/lib/rules/prefer-output-null.js | 1 + 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/rules/no-only-tests.js b/lib/rules/no-only-tests.js index 1c89bcac..49206f61 100644 --- a/lib/rules/no-only-tests.js +++ b/lib/rules/no-only-tests.js @@ -36,6 +36,7 @@ module.exports = { const onlyProperty = test.properties.find( (property) => + property.type === 'Property' && property.key.type === 'Identifier' && property.key.name === 'only' && property.value.type === 'Literal' && diff --git a/lib/rules/prefer-output-null.js b/lib/rules/prefer-output-null.js index a7abfd12..4403b7e8 100644 --- a/lib/rules/prefer-output-null.js +++ b/lib/rules/prefer-output-null.js @@ -48,7 +48,9 @@ module.exports = { */ function getTestInfo(key) { if (test.type === 'ObjectExpression') { - return test.properties.find((item) => item.key.name === key); + return test.properties.find( + (item) => item.type === 'Property' && item.key.name === key + ); } return null; } diff --git a/tests/lib/rules/no-only-tests.js b/tests/lib/rules/no-only-tests.js index 24efa23d..ed892aa6 100644 --- a/tests/lib/rules/no-only-tests.js +++ b/tests/lib/rules/no-only-tests.js @@ -23,7 +23,8 @@ ruleTester.run('no-only-tests', rule, { 'foo', { code: 'foo', foo: true }, RuleTester.somethingElse(), - notRuleTester.only() + notRuleTester.only(), + { ...otherOptions }, ], invalid: [ { code: 'bar', foo: true }, diff --git a/tests/lib/rules/prefer-output-null.js b/tests/lib/rules/prefer-output-null.js index 4fd5014d..910a8093 100644 --- a/tests/lib/rules/prefer-output-null.js +++ b/tests/lib/rules/prefer-output-null.js @@ -25,6 +25,7 @@ ruleTester.run('prefer-output-null', rule, { new RuleTester().run('foo', bar, { valid: [], invalid: [ + { ...otherOptions }, {code: 'foo', output: 'bar', errors: ['bar']}, ] });