fix(pubsub): Remove publish handler object from Arrow Functions

Arrow functions can not access the publish handler object. Do not warn in them.
This commit is contained in:
Dominik Ferber
2015-10-18 00:44:19 +02:00
parent bbf9f22109
commit 7bcbeea82e
2 changed files with 18 additions and 9 deletions

View File

@@ -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])
}
}

View File

@@ -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: [
{