Files
meteor/lib/rules/no-zero-timeout.js
2016-03-09 17:36:58 +01:00

29 lines
799 B
JavaScript

/**
* @fileoverview Prevent usage of Meteor.setTimeout with zero delay
* @author Dominik Ferber
*/
import { isMeteorCall } from '../util/ast'
// -----------------------------------------------------------------------------
// Rule Definition
// -----------------------------------------------------------------------------
export default 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')
}
}
},
})
export const schema = []