From aa5097e4ac9edf7469e4b8428491b085587f1703 Mon Sep 17 00:00:00 2001 From: Mark Chandler Date: Wed, 28 Feb 2018 22:30:44 -0500 Subject: [PATCH 1/2] fix(valid-describe): add check for empty arguments --- rules/__tests__/valid-describe.test.js | 1 + rules/valid-describe.js | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/rules/__tests__/valid-describe.test.js b/rules/__tests__/valid-describe.test.js index 2db4a2c3d..6d4f50f21 100644 --- a/rules/__tests__/valid-describe.test.js +++ b/rules/__tests__/valid-describe.test.js @@ -11,6 +11,7 @@ const ruleTester = new RuleTester({ ruleTester.run('valid-describe', rule, { valid: [ + 'describe()', 'describe("foo", function() {})', 'describe("foo", () => {})', 'describe(`foo`, () => {})', diff --git a/rules/valid-describe.js b/rules/valid-describe.js index a44412c27..60b77edc8 100644 --- a/rules/valid-describe.js +++ b/rules/valid-describe.js @@ -37,6 +37,10 @@ module.exports = { return { CallExpression(node) { if (isDescribe(node)) { + if (!node.arguments.length) { + return; + } + const name = node.arguments[0]; const callbackFunction = node.arguments[1]; if (!isString(name)) { From 9794642a667834b6a3e3bbbaf79645dd12e91825 Mon Sep 17 00:00:00 2001 From: Simen Bekkhus Date: Tue, 13 Mar 2018 20:49:17 +0100 Subject: [PATCH 2/2] fix: disallow empty describe --- rules/__tests__/valid-describe.test.js | 11 ++++++++++- rules/valid-describe.js | 7 +++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/rules/__tests__/valid-describe.test.js b/rules/__tests__/valid-describe.test.js index 6d4f50f21..618184afe 100644 --- a/rules/__tests__/valid-describe.test.js +++ b/rules/__tests__/valid-describe.test.js @@ -11,7 +11,6 @@ const ruleTester = new RuleTester({ ruleTester.run('valid-describe', rule, { valid: [ - 'describe()', 'describe("foo", function() {})', 'describe("foo", () => {})', 'describe(`foo`, () => {})', @@ -72,6 +71,16 @@ ruleTester.run('valid-describe', rule, { }, ], }, + { + code: 'describe()', + errors: [ + { + message: 'Describe requires name and callback arguments', + line: 1, + column: 1, + }, + ], + }, { code: 'describe("foo", async () => {})', errors: [{ message: 'No async describe callback', line: 1, column: 17 }], diff --git a/rules/valid-describe.js b/rules/valid-describe.js index 60b77edc8..3da198064 100644 --- a/rules/valid-describe.js +++ b/rules/valid-describe.js @@ -37,8 +37,11 @@ module.exports = { return { CallExpression(node) { if (isDescribe(node)) { - if (!node.arguments.length) { - return; + if (node.arguments.length === 0) { + return context.report({ + message: 'Describe requires name and callback arguments', + loc: node.loc, + }); } const name = node.arguments[0];