fix(rules): Ignore locus checks with unkown expressions

Instead of aborting when finding an if-statement with unkown statements in the ancestors of any
node, ignore that if-statement. This way the linter will cover more code. Assumes the code never
mixes locus checks with other expressions.
This commit is contained in:
Dominik Ferber
2015-10-18 19:53:48 +02:00
parent 1a1f29e477
commit ff5af1f7ff
5 changed files with 9 additions and 24 deletions

View File

@@ -99,6 +99,8 @@ Executors (client, browser, server, cordova) are detected by looking at the loca
if ((Meteor.isClient || Meteor.isCordova) && !Meteor.isServer) { .. }
```
If a test in a locus check is paired with any other expression that specific locus check will be ignored.
### Package files
ESLint-plugin-Meteor is not able to detect where files in inlined packages are going to be executed. It needs hints to work around this. See [this guide](docs/SETUP_METEOR_PROJECT.md#packages) for details.

View File

@@ -21,10 +21,6 @@ export default function filterExecutorsByAncestors (originalExecutors, ancestors
} else {
invariant(false, 'Block is neither consequent nor alternate of parent')
}
} else {
// can not determine executors, because of unresolvable if-statement
return new Set()
}
}
}

View File

@@ -97,7 +97,7 @@ ruleTester.run('audit-argument-checks', rule(() => ({env: SERVER})), {
Meteor.methods({
foo () {},
foo2 (bar) {
if (true) {
if (!Meteor.isServer) {
check(bar, Meteor.any)
}
}

View File

@@ -119,7 +119,7 @@ ruleTester.run('pubsub - universal', rule(() => ({env: UNIVERSAL})), {
}
`,
`
if (Meteor.Client) {
if (Meteor.isClient) {
if (Meteor.isServer) {
Meteor.subscribe() // not checked because unreachable
}

View File

@@ -158,33 +158,20 @@ describe('filterExecutorsByAncestors', function () {
assert.ok(result.has('server'))
})
it('returns no executors when an unresolvable IfStatement is in ancestors', function () {
it('ignores unresolvable IfStatements is in ancestors', function () {
const consequent = {type: 'BlockStatement'}
const ifConsequent = {
test: {
type: 'MemberExpression',
object: {
type: 'Identifier',
name: 'Meteor'
},
property: {
type: 'Identifier',
name: 'isClient'
}
},
consequent: consequent
}
const result = filterExecutorsByAncestors(new Set(['browser', 'server']), [
{type: 'Program'},
{
type: 'IfStatement',
test: {type: 'Identifier'},
consequent: ifConsequent
consequent: consequent
},
ifConsequent,
consequent
])
assert.equal(result.size, 0)
assert.equal(result.size, 2)
assert.ok(result.has('browser'))
assert.ok(result.has('server'))
})
})