diff --git a/lib/rules/pubsub.js b/lib/rules/pubsub.js index 054ceedc1c..4f1fba2b0a 100644 --- a/lib/rules/pubsub.js +++ b/lib/rules/pubsub.js @@ -59,7 +59,7 @@ module.exports = getMeta => context => { noPublishOnClient(node) } else { expectTwoArguments(node) - if (node.arguments.length >= 2) { + if (node.arguments.length >= 2 && node.arguments[1].type !== 'ArrowFunctionExpression') { markAsMeteorPublicationFn(node.arguments[1]) } } diff --git a/tests/lib/rules/pubsub.js b/tests/lib/rules/pubsub.js index d1b3ee376a..c0c8e365da 100644 --- a/tests/lib/rules/pubsub.js +++ b/tests/lib/rules/pubsub.js @@ -23,18 +23,16 @@ const commonValidTests = [ `if (Meteor.isCordova) { Meteor.subscribe('foo', { bar: true }) }`, `if (Meteor.isServer) { Meteor.publish('foo', function () {}) }`, `if (Meteor.isServer) { Meteor.publish('foo', function (a) {}) }`, - { - code: `if (Meteor.isServer) { Meteor.publish('foo', (a) => { return [] }) }`, - parser: 'babel-eslint' - }, { code: ` if (Meteor.isServer) { - Meteor.publish('foo', () => { + Meteor.publish('foo', (a) => { + + // no publish handler object available in arrow functions, + // but valid anyways return [] }) - } - `, + }`, parser: 'babel-eslint' }, ` @@ -126,7 +124,18 @@ ruleTester.run('pubsub - universal', rule(() => ({env: UNIVERSAL})), { Meteor.subscribe() // not checked because unreachable } } - ` + `, + { + code: ` + if (Meteor.isServer) { + Meteor.publish('foo', () => { + this.userId() // valid because this is not a publication fn + return [] + }) + } + `, + parser: 'babel-eslint' + } ], invalid: [ {