feat(audit-arguments-check): audit when fn is defined by computed props as well

This commit is contained in:
Dominik Ferber
2015-09-28 00:43:20 +02:00
parent 191e975107
commit ae05984c03
2 changed files with 16 additions and 3 deletions

View File

@@ -55,12 +55,14 @@ module.exports = function (context) {
CallExpression: (node) => {
if (
node.callee.type === 'MemberExpression' &&
!node.callee.computed &&
node.callee.object.type === 'Identifier' && node.callee.object.name === 'Meteor'
) {
// publications
if (node.callee.property.name === 'publish') {
if (
(node.callee.property.type === 'Identifier' && node.callee.property.name === 'publish') ||
(node.callee.property.type === 'Literal' && node.callee.property.value === 'publish')
) {
if (node.arguments.length < 2) {
return;
}
@@ -69,7 +71,10 @@ module.exports = function (context) {
}
// method
if (node.callee.property.name === 'methods') {
if (
(node.callee.property.type === 'Identifier' && node.callee.property.name === 'methods') ||
(node.callee.property.type === 'Literal' && node.callee.property.value === 'methods')
) {
if (
node.arguments.length > 0 &&
node.arguments[0].type === 'ObjectExpression'

View File

@@ -32,6 +32,7 @@ ruleTester.run('audit-argument-checks', rule, {
'Meteor.methods()',
'Meteor.methods({ x: function () {} })',
'Meteor["methods"]({ x: function () {} })',
'Meteor.methods({ x: true })',
{code: 'Meteor.methods({ x () {} })', parser: 'babel-eslint'},
'Meteor.methods({ x: function (bar) { check(bar, Match.Any); } })',
@@ -46,6 +47,13 @@ ruleTester.run('audit-argument-checks', rule, {
type: 'Identifier'
}]
},
{
code: 'Meteor["publish"]("foo", function (bar) { foo(); })',
errors: [{
message: 'bar is not checked',
type: 'Identifier'
}]
},
{
code: 'Meteor.publish("foo", function (bar) {})',
errors: [{