mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
fix(collections): Allow declaration of collection
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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')
|
||||
}
|
||||
|
||||
@@ -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'}
|
||||
|
||||
Reference in New Issue
Block a user