polling-interval-too-short
Ast Rule: function call
polling-interval-too-short
function visit(node, filename, code) {
if (node.functionName && node.functionName.value) {
if (node.arguments && node.arguments.values && node.arguments.values.length == 2) {
const secondArgument = node.arguments.values[1];
if (secondArgument && secondArgument.value) {
const secondArgumentValue = secondArgument.value;
if (secondArgumentValue.astType === "object") {
const pollIntervalValues = secondArgumentValue.elements.filter(e => e.name && e.name.value === "pollInterval");
if (pollIntervalValues && pollIntervalValues.length > 0) {
const pollIntervalValue = pollIntervalValues[0];
if (pollIntervalValue.value && pollIntervalValue.value.astType === "string") {
if (pollIntervalValue.value.value < 100) {
const error = buildError(pollIntervalValue.start.line, pollIntervalValue.start.col,
pollIntervalValue.end.line, pollIntervalValue.end.col,
"Poll interval too short and risk of overloading the backend, put a value higher than 100ms", "WARNING", "BEST_PRACTICE");
const edit = buildEditUpdate(pollIntervalValue.value.start.line, pollIntervalValue.value.start.col,
pollIntervalValue.value.end.line, pollIntervalValue.value.end.col, "100");
const fix = buildFix("change the polling interval to 100", [edit]);
addError(error.addFix(fix));
}
}
}
}
}
}
}
}
large-poll-interval.js
Expected test result: no error
too-short.js
Expected test result: has error
no-poll-interval.js
Expected test result: no error