Files
meteor/lib/rules/no-zero-timeout.js
Dominik Ferber c818fb07d5 feat(rules): remove a ton of rules
This further gets rid of all environment checks, keeping it simple

no longer support environments
2016-03-02 13:52:20 +01:00

29 lines
803 B
JavaScript

/**
* @fileoverview Prevent usage of Meteor.setTimeout with zero delay
* @author Dominik Ferber
*/
import { isMeteorCall } from '../util/ast'
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
module.exports = context => ({
CallExpression: (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 = []