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