From 102bf5e56a8b9f61d89aec306059f61490d95213 Mon Sep 17 00:00:00 2001 From: Riccardo Coccioli Date: Thu, 14 Jan 2016 10:28:49 +0100 Subject: [PATCH] Fix JSHint warnings Fix JSHint warnings --- lib/helpers.js | 2 +- proxy.js | 19 ++++++++++++------- stats.js | 19 ++++++++++--------- 3 files changed, 23 insertions(+), 17 deletions(-) diff --git a/lib/helpers.js b/lib/helpers.js index 52ba3a3f..c0ab9646 100644 --- a/lib/helpers.js +++ b/lib/helpers.js @@ -49,6 +49,6 @@ function is_valid_packet(fields) { return true; } -}; +} exports.is_valid_packet = is_valid_packet; diff --git a/proxy.js b/proxy.js index 507aa941..791bbadf 100644 --- a/proxy.js +++ b/proxy.js @@ -1,3 +1,5 @@ +/*jshint node:true, laxcomma:true */ + var dgram = require('dgram') , net = require('net') , events = require('events') @@ -26,7 +28,7 @@ configlib.configFile(process.argv[2], function (conf, oldConfig) { var logPrefix = "[" + process.pid + "] "; var log = function(msg, type) { l.log(logPrefix + msg, type); - } + }; if (forkCount > 1 && cluster.isMaster) { @@ -68,15 +70,18 @@ configlib.configFile(process.argv[2], function (conf, oldConfig) { var server = servermod.start(config, function (msg, rinfo) { // Convert the raw packet to a string (defaults to UTF8 encoding) var packet_data = msg.toString(); + var current_metric + , bits + , key; // If the packet contains a \n then it contains multiple metrics if (packet_data.indexOf("\n") > -1) { var metrics; metrics = packet_data.split("\n"); // Loop through the metrics and split on : to get mertric name for hashing for (var midx in metrics) { - var current_metric = metrics[midx]; - var bits = current_metric.split(':'); - var key = bits.shift(); + current_metric = metrics[midx]; + bits = current_metric.split(':'); + key = bits.shift(); if (current_metric !== '') { var new_msg = new Buffer(current_metric); packet.emit('send', key, new_msg); @@ -85,9 +90,9 @@ configlib.configFile(process.argv[2], function (conf, oldConfig) { } else { // metrics needs to be an array to fake it for single metric packets - var current_metric = packet_data; - var bits = current_metric.split(':'); - var key = bits.shift(); + current_metric = packet_data; + bits = current_metric.split(':'); + key = bits.shift(); if (current_metric !== '') { packet.emit('send', key, msg); } diff --git a/stats.js b/stats.js index 9e10f1a8..a6a0b479 100644 --- a/stats.js +++ b/stats.js @@ -206,11 +206,12 @@ config.configFile(process.argv[2], function (config) { var handlePacket = function (msg, rinfo) { backendEvents.emit('packet', msg, rinfo); counters[packets_received]++; + var metrics; var packet_data = msg.toString(); if (packet_data.indexOf("\n") > -1) { - var metrics = packet_data.split("\n"); + metrics = packet_data.split("\n"); } else { - var metrics = [ packet_data ] ; + metrics = [ packet_data ] ; } for (var midx in metrics) { @@ -278,16 +279,16 @@ config.configFile(process.argv[2], function (config) { } stats.messages.last_msg_seen = Math.round(new Date().getTime() / 1000); - } + }; // If config.servers isn't specified, use the top-level config for backwards-compatibility - var server_config = config.servers || [config] + var server_config = config.servers || [config]; for (var i = 0; i < server_config.length; i++) { // The default server is UDP - var server = server_config[i].server || './servers/udp' - startServer(server_config[i], server, handlePacket) + var server = server_config[i].server || './servers/udp'; + startServer(server_config[i], server, handlePacket); } - serversLoaded = true + serversLoaded = true; mgmtServer = net.createServer(function(stream) { stream.setEncoding('ascii'); @@ -431,8 +432,8 @@ config.configFile(process.argv[2], function (config) { config.flushInterval = flushInterval; if (config.backends) { - for (var i = 0; i < config.backends.length; i++) { - loadBackend(config, config.backends[i]); + for (var j = 0; j < config.backends.length; j++) { + loadBackend(config, config.backends[j]); } } else { // The default backend is graphite