mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
feat(globals): Enable setting collection globals through settings
Settings can now be used to tell the linter about collections. It marks them as globals for now. In the future such variables will be linted in special ways by the rule collections, which does not exist yet.
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
This rule defines global variables based on the environment the file is executed in.
|
||||
This rule never emits warnings on its own. It is meant to be used with ESLint's `no-undef`.
|
||||
|
||||
Do not use the Meteor environment.
|
||||
This rule also marks collections defined through settings as globals.
|
||||
|
||||
## Rule Details
|
||||
|
||||
@@ -22,6 +22,18 @@ Do not use the Meteor environment (`env: meteor` in `.eslintrc` or `$ eslint ./
|
||||
}
|
||||
```
|
||||
|
||||
Collections defined in `.eslintrc`'s settings will be marked as globals as well.
|
||||
|
||||
```js
|
||||
|
||||
settings: {
|
||||
meteor: {
|
||||
collections: ['Posts', 'Items'] // all universal collections
|
||||
}
|
||||
}
|
||||
|
||||
```
|
||||
|
||||
## Further Reading
|
||||
|
||||
- http://eslint.org/docs/1.0.0/rules/no-undef
|
||||
|
||||
@@ -49,6 +49,12 @@ module.exports = getMeta => context => {
|
||||
variables.push(generateGlobalVariable(globalVar, globalScope))
|
||||
}
|
||||
})
|
||||
|
||||
// add Collections to globals
|
||||
const {collections = []} = context.settings.meteor
|
||||
collections.map(collection => {
|
||||
variables.push(generateGlobalVariable(collection, globalScope))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,14 +20,11 @@ import {SERVER, PACKAGE, NON_METEOR} from '../../../dist/util/environment'
|
||||
|
||||
const ruleTester = new RuleTester()
|
||||
ruleTester.run('globals', rule(() => ({env: SERVER})), {
|
||||
|
||||
valid: ['Session.set("hi", true)'],
|
||||
invalid: []
|
||||
|
||||
})
|
||||
|
||||
ruleTester.run('globals', rule(() => ({env: PACKAGE})), {
|
||||
|
||||
valid: [
|
||||
`
|
||||
/* eslint-meteor-env client, server */
|
||||
@@ -40,10 +37,18 @@ ruleTester.run('globals', rule(() => ({env: PACKAGE})), {
|
||||
`
|
||||
/* eslint-meteor-env server */
|
||||
Session.set("hi", true)
|
||||
`
|
||||
`,
|
||||
{
|
||||
code: 'Users.find()',
|
||||
settings: {meteor: {collections: ['Users']}}
|
||||
},
|
||||
{
|
||||
code: 'Users.find()',
|
||||
settings: {meteor: {}}
|
||||
}
|
||||
],
|
||||
invalid: []
|
||||
|
||||
invalid: []
|
||||
})
|
||||
|
||||
ruleTester.run('globals', rule(() => ({env: NON_METEOR})), {
|
||||
|
||||
Reference in New Issue
Block a user