fix(collections): Allow declaration of collection

This commit is contained in:
Dominik Ferber
2015-10-21 21:32:09 +02:00
parent 19cbbe6353
commit 659ec630bf
3 changed files with 10 additions and 8 deletions

View File

@@ -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

View File

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

View File

@@ -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'}