Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fix(valid-describe): add check for empty arguments #94

Merged
merged 2 commits into from
Mar 13, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rules/__tests__/valid-describe.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const ruleTester = new RuleTester({

ruleTester.run('valid-describe', rule, {
valid: [
'describe()',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An empty describe isn't valid - could you make it be a linting error instead?

Copy link
Member

@SimenB SimenB Mar 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a

if (node.arguments.length < 2) {
  context.report({
    message: '`describe` requires 2 arguments',
    loc: paramsLocation(node.arguments),
  });
  return;
}

or something similar

'describe("foo", function() {})',
'describe("foo", () => {})',
'describe(`foo`, () => {})',
Expand Down
4 changes: 4 additions & 0 deletions rules/valid-describe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down