mirror of
https://github.com/meteor/meteor.git
synced 2026-05-02 03:01:46 -04:00
Also fixes a bug in audit-argument-checks where it would show errors in non-meteor blocks. BREAKING CHANGE: Envs specified through comments are now restricted to client and server.
50 lines
1.3 KiB
JavaScript
50 lines
1.3 KiB
JavaScript
/**
|
|
* @fileoverview Prevent usage of Meteor.setTimeout with zero delay
|
|
* @author Dominik Ferber
|
|
*/
|
|
|
|
import {NON_METEOR} from '../util/environment'
|
|
import {getExecutors} from '../util'
|
|
import {isMeteorCall} from '../util/ast'
|
|
|
|
// -----------------------------------------------------------------------------
|
|
// Rule Definition
|
|
// -----------------------------------------------------------------------------
|
|
|
|
module.exports = getMeta => context => {
|
|
|
|
const {env} = getMeta(context)
|
|
|
|
// -------------------------------------------------------------------------
|
|
// Public
|
|
// -------------------------------------------------------------------------
|
|
|
|
if (env === NON_METEOR) {
|
|
return {}
|
|
}
|
|
|
|
return {
|
|
|
|
CallExpression: function (node) {
|
|
if (isMeteorCall(node, 'setTimeout')) {
|
|
const executors = getExecutors(env, context.getAncestors())
|
|
if (!executors.has('browser') && !executors.has('cordova')) {
|
|
return
|
|
}
|
|
|
|
if (node.arguments.length === 1) {
|
|
context.report(node, 'Implicit timeout of 0')
|
|
} else if (
|
|
node.arguments.length > 1 && node.arguments[1].type === 'Literal' && node.arguments[1].value === 0
|
|
) {
|
|
context.report(node, 'Timeout of 0. Use `Meteor.defer` instead')
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
module.exports.schema = []
|