Skip to content
This repository has been archived by the owner on Sep 11, 2018. It is now read-only.

Commit

Permalink
Add linters and fix style errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dwick committed Jan 12, 2015
1 parent 5be6291 commit 890ce01
Show file tree
Hide file tree
Showing 15 changed files with 360 additions and 124 deletions.
111 changes: 111 additions & 0 deletions .jscsrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
{
"disallowQuotedKeysInObjects": true,
"validateQuoteMarks": "'",
"disallowSpacesInFunctionExpression": {
"beforeOpeningRoundBrace": true
},
"disallowSpacesInFunctionDeclaration": {
"beforeOpeningRoundBrace": true
},
"requireSpacesInFunctionExpression": {
"beforeOpeningCurlyBrace": true
},
"requireSpacesInFunctionDeclaration": {
"beforeOpeningCurlyBrace": true
},
"requireParenthesesAroundIIFE": true,
"requireDotNotation": true,
"disallowMultipleVarDecl": true,
"requireCurlyBraces": [
"if",
"else",
"for",
"while",
"do",
"try",
"catch"
],
"disallowTrailingWhitespace": true,
"disallowMixedSpacesAndTabs": true,
"validateIndentation": 2,
"disallowSpaceAfterPrefixUnaryOperators": [
"++",
"--",
"+",
"-",
"~",
"!"
],
"disallowSpaceBeforePostfixUnaryOperators": [
"++",
"--"
],
"requireSpaceBeforeBinaryOperators": true,
"requireSpaceAfterBinaryOperators": true,
"disallowNewlineBeforeBlockStatements": true,
"validateLineBreaks": "LF",
"validateParameterSeparator": ", ",
"requireCommaBeforeLineBreak": true,
"requireTrailingComma": {
"ignoreSingleLine": true
},
"requireCamelCaseOrUpperCaseIdentifiers": "ignoreProperties",
"requireCapitalizedConstructors": true,
"requireSpaceAfterKeywords": [
"do",
"for",
"if",
"else",
"switch",
"case",
"try",
"catch",
"void",
"while",
"with",
"return",
"typeof"
],
"requireSpaceBeforeBlockStatements": true,
"requireSpacesInConditionalExpression": {
"afterTest": true,
"beforeConsequent": true,
"afterConsequent": true,
"beforeAlternate": true
},
"disallowSpacesInCallExpression": true,
"requireBlocksOnNewline": true,
"disallowEmptyBlocks": true,
"disallowSpacesInsideParentheses": true,
"requireSpacesInsideObjectBrackets": "all",
"disallowSpacesInsideArrayBrackets": "all",
"disallowSpaceAfterObjectKeys": true,
"requireSpaceBeforeObjectValues": true,
"requireOperatorBeforeLineBreak": [
"?",
"=",
"+",
"-",
"/",
"*",
"==",
"===",
"!=",
"!==",
">",
">=",
"<",
"<="
],
"disallowKeywords": [
"with"
],
"disallowMultipleLineStrings": true,
"disallowMultipleLineBreaks": true,
"disallowKeywordsOnNewLine": [
"else"
],
"requireLineFeedAtFileEnd": true,
"disallowYodaConditions": true,
"requireSpaceAfterLineComment": true
}
51 changes: 51 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
/*
* ENVIRONMENTS
* =================
*/

// Define globals exposed by Node.js.
"node": true,

/*
* ENFORCING OPTIONS
* =================
*/

// Force all variable names to use either camelCase style or UPPER_CASE
// with underscores.
"camelcase": true,

// Prohibit use of == and != in favor of === and !==.
"eqeqeq": true,

// Suppress warnings about == null comparisons.
"eqnull": true,

// Enforce tab width of 2 spaces.
"indent": 2,

// Prohibit use of a variable before it is defined.
"latedef": true,

// Require capitalized names for constructor functions.
"newcap": true,

// Enforce use of single quotation marks for strings.
"quotmark": "single",

// Prohibit trailing whitespace.
"trailing": true,

// Prohibit use of explicitly undeclared variables.
"undef": true,

// Warn when variables are defined but never used.
"unused": "var",

// Enforce line length to 80 characters
"maxlen": 80,

// Enforce placing 'use strict' at the top function scope
"strict": true
}
18 changes: 10 additions & 8 deletions example/config.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use strict';

var Statsd = require('metron').dataAdapters.Statsd;
var statsd = new Statsd({
host: process.env.statsd_host,
port: process.env.statsd_port,
host: process.env.STATDSD_HOST,
port: process.env.STATSD_PORT,
});

var intConfig = {
type: 'number',
min: 0,
max: 100
max: 100,
};

var stringConfig = {
type: 'string',
length: 256
length: 256,
};

var config = {
Expand All @@ -30,9 +32,9 @@ var config = {
domContentLoadedTiming: intConfig,
actionName: stringConfig,
verification: stringConfig,
}
}
}
}
},
},
},
};

module.exports = config;
5 changes: 2 additions & 3 deletions example/index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
var Metron = require('../src/metron'),
config = require ('./config.js');
var Metron = require('../src/metron');
var config = require('./config.js');

var server = new Metron(config);
server.start();

console.log('Server started at http://localhost:' + server.get('port'));

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"description": "simple whitelisted statsd passthrough.",
"main": "src/metron.js",
"scripts": {
"lint": "jshint . && jscs .",
"test": "./node_modules/mocha/bin/mocha"
},
"repository": {
Expand Down
10 changes: 5 additions & 5 deletions src/data/log.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/* jshint strict:false */
'use strict';

var crypto = require('crypto');
var utils = require('../utils');

Expand All @@ -25,14 +26,14 @@ Log.prototype.format = function(segment, config, req) {

var format = config.log.format || this.config.format;
return format(segment, req);
}
};

Log.prototype.save = function(logString, config) {
config.log = config.log || {};

var save = config.log.save || this.config.save;
return save(logString, config);
}
};

Log.prototype.send = function(segment, config, req) {
config.log = config.log || {};
Expand All @@ -44,7 +45,6 @@ Log.prototype.send = function(segment, config, req) {

var logString = this.format(segment, config, req);
this.save(logString, config);
}
};

module.exports = Log;

32 changes: 16 additions & 16 deletions src/data/statsd.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
/* jshint strict:false */
'use strict';

var dgram = require('dgram');
var dns = require('dns');
var utils = require('../utils')
var utils = require('../utils');

var defaultStatsdConfig = {
host: 'localhost',
port: 8125,
socketTimeout: 500,
prefix: '',
preCacheDNS: true,
bufferTimeout: 500
bufferTimeout: 500,
};

function Statsd(config) {
Expand All @@ -35,7 +35,7 @@ function Statsd(config) {

Statsd.prototype.stop = function() {
this.socket.close();
}
};

Statsd.prototype.send = function(segment, config, req) {
config.statsd = config.statsd || {};
Expand All @@ -57,18 +57,18 @@ Statsd.prototype.send = function(segment, config, req) {
message = Statsd[config.statsd.eventType](name, value);

if (config.statsd.sampleRate) {
message += '|@' + config.statsd.sampleRate
message += '|@' + config.statsd.sampleRate;
}

if (config.statsd.tags) {
message += '|#' + config.statsd.tags.join(',')
message += '|#' + config.statsd.tags.join(',');
}

this.buffer.push(message);
}).bind(this));

this.flushBuffer();
}
};

Statsd.prototype.flushBuffer = function() {
if (!this.config.bufferTimeout) {
Expand All @@ -92,13 +92,13 @@ Statsd.prototype.flushBuffer = function() {
this.config.bufferTimeout);
}
}
}
};

Statsd.prototype.flushToSocket = function() {
var buffer = new Buffer(this.buffer.join('\n'));
this.buffer = [];

if(buffer.length === 0) {
if (buffer.length === 0) {
return;
}

Expand All @@ -117,30 +117,30 @@ Statsd.prototype.flushToSocket = function() {
this.log(buffer.length);
this.log(this.config.host + ':' + this.config.port);
}
}
};

Statsd.counter = function(name, value) {
return name + ':' + value + '|c';
}
};

Statsd.increment = function(name, value) {
return Statsd.counter(name, value || 1);
}
};

Statsd.decrement = function(name, value) {
return Statsd.counter(name, -value || -1);
}
};

Statsd.gauge = function(name, value) {
return name + ':' + value + '|g';
}
};

Statsd.timing = function(name, value) {
return name + ':' + value + '|ms';
}
};

Statsd.set = function(name, value) {
return name + ':' + value + '|s';
}
};

module.exports = Statsd;
Loading

0 comments on commit 890ce01

Please sign in to comment.