From 659ec630bf22e67acc7a557cdb40c28d84dbe38f Mon Sep 17 00:00:00 2001 From: Dominik Ferber Date: Wed, 21 Oct 2015 21:32:09 +0200 Subject: [PATCH] fix(collections): Allow declaration of collection --- docs/rules/collections.md | 6 +----- lib/rules/collections.js | 6 ++++-- tests/lib/rules/collections.js | 6 +++++- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docs/rules/collections.md b/docs/rules/collections.md index f50f30ae0a..70e5b7f5b8 100644 --- a/docs/rules/collections.md +++ b/docs/rules/collections.md @@ -73,13 +73,9 @@ Example of an `.eslintrc` file declaring the collections `Users` and `Posts`: - [Mongo.ObjectID](http://docs.meteor.com/#/full/mongo_object_id) - [Mongo Cursors](http://docs.meteor.com/#/full/mongo_cursor) - Arguments to collection methods, e.g. `find()` +- Does not warn when declaring the same collection multiple times ## Further Reading - http://docs.meteor.com/#/full/collections - - -## Possible Improvements - -* Verify arguments to collection methods diff --git a/lib/rules/collections.js b/lib/rules/collections.js index ae365afc57..8c10672741 100644 --- a/lib/rules/collections.js +++ b/lib/rules/collections.js @@ -163,8 +163,10 @@ module.exports = getMeta => context => { if ( node.left.type === 'Identifier' && collectionExists(node.left.name) && - node.right.type === 'NewExpression' && - isMongoCollection(node.right.callee, 'Collection') + ( + node.right.type !== 'NewExpression' || + !isMongoCollection(node.right.callee, 'Collection') + ) ) { context.report(node, 'Can not overwrite collection') } diff --git a/tests/lib/rules/collections.js b/tests/lib/rules/collections.js index 74b0c448cc..0f9297c561 100644 --- a/tests/lib/rules/collections.js +++ b/tests/lib/rules/collections.js @@ -32,6 +32,10 @@ const commonValidCode = [ new Mongo.Collection() } `, + { + code: 'Users = new Mongo.Collection("users")', + settings: {meteor: {collections: ['Users']}} + }, { code: 'Users.find()', settings: {meteor: {collections: ['Users']}} @@ -124,7 +128,7 @@ const commonInvalidCode = [ ] }, { - code: 'Users = new Mongo.Collection("users")', + code: 'Users = true', settings: {meteor: {collections: ['Users']}}, errors: [ {message: 'Can not overwrite collection', type: 'AssignmentExpression'}