Files
meteor/lib/rules/no-zero-timeout.js
Dominik Ferber 0b9622dedd fix(internal): Add locus resloving capabilities
Resolve all Meteor.isClient, Meteor.isServer and Meteor.isCordova LogicalExpressions
2015-10-13 18:42:31 +02:00

43 lines
1.1 KiB
JavaScript

/**
* @fileoverview Prevent usage of Meteor.setTimeout with zero delay
* @author Dominik Ferber
*/
import {isMeteorCall} from '../util/ast'
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
module.exports = getMeta => context => {
const {isLintedEnv} = getMeta(context.getFilename())
// -------------------------------------------------------------------------
// Public
// -------------------------------------------------------------------------
if (!isLintedEnv) {
return {}
}
return {
CallExpression: function (node) {
if (isMeteorCall(node, 'setTimeout')) {
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 = []