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:
Dominik Ferber
2015-10-21 17:46:03 +02:00
parent a2144b5e43
commit 0908b6c7b7
3 changed files with 29 additions and 6 deletions

View File

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

View File

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

View File

@@ -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})), {