Skip to content

Commit

Permalink
introduce eslint and consistent 4-space indents
Browse files Browse the repository at this point in the history
* I would really prefer 2-space indents, like 90+% of the JS world, but
I value internal consistency higher than external conformity
  • Loading branch information
msimerson committed Sep 22, 2015
1 parent 8b9bf78 commit 72a58de
Show file tree
Hide file tree
Showing 54 changed files with 617 additions and 586 deletions.
8 changes: 8 additions & 0 deletions .eslintrc
@@ -0,0 +1,8 @@
{
"env": {
"node": true
},
"rules": {
"indent": [2, 4, {"SwitchCase": 1}],
}
}
10 changes: 6 additions & 4 deletions .travis.yml
@@ -1,11 +1,12 @@
language: node_js
node_js:
- "0.12"
- "0.10"
# - "0.8" # no longer supported by iconv
# - "0.6" # no longer supported by async
- "stable"
- "0.10"
- "0.12"
- "iojs-v3"
- "stable"

services:
- redis-server

Expand All @@ -22,4 +23,5 @@ env:

after_success:
- npm run coveralls
sudo: false

sudo: false
17 changes: 14 additions & 3 deletions Gruntfile.js
@@ -1,12 +1,23 @@
'use strict';

module.exports = function(grunt) {

grunt.loadNpmTasks('grunt-contrib-clean');
grunt.loadNpmTasks('grunt-eslint');
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-version-check');

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
eslint: {
main: {
src: ['*.js', 'bin/**/*.js', 'plugins/**/*.js']
},
test: {
src: ['tests/**/*.js'],
}
},
jshint: {
options: {
jshintrc: true,
Expand All @@ -15,19 +26,19 @@ module.exports = function(grunt) {
bin: [ 'bin/**/*.js' ],
plugins: [ 'plugins/**/*.js' ],
test: [ 'tests/**/*.js' ],
all: [ '<%= jshint.nosql %>', '<%= jshint.test %>' ],
},
clean: {
cruft: ['npm-debug.log'],
dist: [ 'node_modules' ]
},
versioncheck: {
options: {
skip : ['semver', 'npm'],
hideUpToDate : false
skip : ['semver', 'npm'],
hideUpToDate : false
}
},
});

grunt.registerTask('lint', ['eslint']);
grunt.registerTask('default', ['jshint']);
};
50 changes: 26 additions & 24 deletions chunkemitter.js
Expand Up @@ -13,33 +13,35 @@ function ChunkEmitter(buffer_size) {
util.inherits(ChunkEmitter, EventEmitter);

if (!Buffer.concat) {
var buf;
Buffer.concat = function(list, length) {
if (!Array.isArray(list)) {
throw new Error('Usage: Buffer.concat(list, [length])');
}
if (!Array.isArray(list)) {
throw new Error('Usage: Buffer.concat(list, [length])');
}

if (list.length === 0) {
return new Buffer(0);
} else if (list.length === 1) {
return list[0];
}
if (list.length === 0) {
return new Buffer(0);
} else if (list.length === 1) {
return list[0];
}

if (typeof length !== 'number') {
length = 0;
for (var i = 0; i < list.length; i++) {
var buf = list[i];
length += buf.length;
if (typeof length !== 'number') {
length = 0;
for (var i = 0; i < list.length; i++) {
buf = list[i];
length += buf.length;
}
}
}

var buffer = new Buffer(length);
var pos = 0;
for (var i = 0; i < list.length; i++) {
var buf = list[i];
buf.copy(buffer, pos);
pos += buf.length;
}
return buffer;
var buffer = new Buffer(length);
var pos = 0;

for (var i = 0; i < list.length; i++) {
buf = list[i];
buf.copy(buffer, pos);
pos += buf.length;
}
return buffer;
};
}

Expand Down Expand Up @@ -81,7 +83,7 @@ ChunkEmitter.prototype.fill = function (input) {
this.pos += to_write;
input = input.slice(to_write);
}
}
};

ChunkEmitter.prototype.end = function (cb) {
var emitted = false;
Expand All @@ -100,6 +102,6 @@ ChunkEmitter.prototype.end = function (cb) {
this.bufs_size = 0;
if (cb && typeof cb === 'function') cb();
return emitted;
}
};

module.exports = ChunkEmitter;
2 changes: 1 addition & 1 deletion config.js
Expand Up @@ -61,7 +61,7 @@ config.arrange_args = function (args) {
}

if (!fs_type) {
if (/\.json$/.test(fs_name)) fs_type = 'json';
if (/\.json$/.test(fs_name)) fs_type = 'json';
else if (/\.yaml$/.test(fs_name)) fs_type = 'yaml';
else if (/\.ini$/.test(fs_name)) fs_type = 'ini';
else fs_type = 'value';
Expand Down
24 changes: 12 additions & 12 deletions connection.js
Expand Up @@ -587,18 +587,18 @@ Connection.prototype.reset_transaction_respond = function (retval, msg, cb) {
};

Connection.prototype.init_transaction = function(cb) {
var self = this;
this.reset_transaction(function () {
self.transaction = trans.createTransaction(self.tran_uuid());
// Catch any errors from the message_stream
self.transaction.message_stream.on('error', function (err) {
self.logcrit('message_stream error: ' + err.message);
self.respond('421', 'Internal Server Error', function () {
self.disconnect();
});
});
self.transaction.results = new ResultStore(self);
if (cb) cb();
var self = this;
this.reset_transaction(function () {
self.transaction = trans.createTransaction(self.tran_uuid());
// Catch any errors from the message_stream
self.transaction.message_stream.on('error', function (err) {
self.logcrit('message_stream error: ' + err.message);
self.respond('421', 'Internal Server Error', function () {
self.disconnect();
});
});
self.transaction.results = new ResultStore(self);
if (cb) cb();
});
};

Expand Down
18 changes: 9 additions & 9 deletions dkim.js
Expand Up @@ -49,7 +49,7 @@ function Buf() {

// There is one DKIMObject created for each signature found

function DKIMObject(header, header_idx, cb, timeout) {
function DKIMObject (header, header_idx, cb, timeout) {
this.cb = cb;
this.sig = header;
this.sig_md5 = md5(header);
Expand Down Expand Up @@ -339,7 +339,7 @@ DKIMObject.prototype.end = function () {
return self.result('invalid version', 'invalid');
}
if (self.dns_fields.g) {
if (self.dns_fields.g !== '*') {
if (self.dns_fields.g !== '*') {
var s = self.dns_fields.g;
// Escape any special regexp characters
s = s.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
Expand All @@ -357,13 +357,13 @@ DKIMObject.prototype.end = function () {
return self.result('inapplicable key', 'invalid');
}
if (self.dns_fields.h) {
var hashes = self.dns_fields.h.split(':');
for (var h=0; h<hashes.length; h++) {
var hash = hashes[h].trim();
if (self.fields.a.indexOf(hash) === -1) {
return self.result('inappropriate hash algorithm', 'invalid');
}
}
var hashes = self.dns_fields.h.split(':');
for (var h=0; h<hashes.length; h++) {
var hash = hashes[h].trim();
if (self.fields.a.indexOf(hash) === -1) {
return self.result('inappropriate hash algorithm', 'invalid');
}
}
}
if (self.dns_fields.k) {
if (self.fields.a.indexOf(self.dns_fields.k) === -1) {
Expand Down
17 changes: 10 additions & 7 deletions fsync_writestream.js
Expand Up @@ -35,18 +35,21 @@ if (version > 0 || subversion >= 10) {

function close(fd) {
fs.fsync(fd || self.fd, function(er) {
if (er)
self.emit('error', er);
if (er) {
self.emit('error', er);
}
else {
fs.close(fd || self.fd, function(er) {
if (er)
self.emit('error', er);
else
self.emit('close');
if (er) {
self.emit('error', er);
}
else {
self.emit('close');
}
});
self.fd = null;
}
})
});
}
};
}
Expand Down
46 changes: 23 additions & 23 deletions outbound.js
Expand Up @@ -41,7 +41,7 @@ exports.load_config = function () {
'-always_split',
'-enable_tls', // TODO: default to enabled in Haraka 3.0
'-ipv6_enabled',
],
],
}, function () {
exports.load_config();
}).main;
Expand Down Expand Up @@ -354,7 +354,7 @@ exports.send_email = function () {
var from = arguments[0],
to = arguments[1],
contents = arguments[2];
var next = arguments[3];
var next = arguments[3];

this.loginfo("Sending email via params");

Expand Down Expand Up @@ -774,29 +774,29 @@ HMailItem.prototype.get_mx = function () {
HMailItem.prototype.get_mx_respond = function (retval, mx) {
switch(retval) {
case constants.ok:
var mx_list;
if (Array.isArray(mx)) {
mx_list = mx;
}
else if (typeof mx === "object") {
mx_list = [mx];
}
else {
// assume string
var matches = /^(.*?)(:(\d+))?$/.exec(mx);
if (!matches) {
throw("get_mx returned something that doesn't match hostname or hostname:port");
}
mx_list = [{priority: 0, exchange: matches[1], port: matches[3]}];
var mx_list;
if (Array.isArray(mx)) {
mx_list = mx;
}
else if (typeof mx === "object") {
mx_list = [mx];
}
else {
// assume string
var matches = /^(.*?)(:(\d+))?$/.exec(mx);
if (!matches) {
throw("get_mx returned something that doesn't match hostname or hostname:port");
}
this.logdebug("Got an MX from Plugin: " + this.todo.domain + " => 0 " + mx);
return this.found_mx(null, mx_list);
mx_list = [{priority: 0, exchange: matches[1], port: matches[3]}];
}
this.logdebug("Got an MX from Plugin: " + this.todo.domain + " => 0 " + mx);
return this.found_mx(null, mx_list);
case constants.deny:
this.logwarn("get_mx plugin returned DENY: " + mx);
return this.bounce("No MX for " + this.domain);
this.logwarn("get_mx plugin returned DENY: " + mx);
return this.bounce("No MX for " + this.domain);
case constants.denysoft:
this.logwarn("get_mx plugin returned DENYSOFT: " + mx);
return this.temp_fail("Temporary MX lookup error for " + this.domain);
this.logwarn("get_mx plugin returned DENYSOFT: " + mx);
return this.temp_fail("Temporary MX lookup error for " + this.domain);
}

var hmail = this;
Expand Down Expand Up @@ -945,7 +945,7 @@ HMailItem.prototype.try_deliver = function () {
return self.try_deliver_host(mx);
}

host = mx.exchange;
host = mx.exchange;
var family = mx.family;

this.loginfo("Looking up " + family + " records for: " + host);
Expand Down
4 changes: 3 additions & 1 deletion package.json
Expand Up @@ -40,10 +40,12 @@
"nodeunit" : "https://github.com/godsflaw/nodeunit/archive/master.tar.gz",
"jscoverage" : "*",
"coveralls" : "*",
"eslint" : "^1.5.0",
"grunt" : "*",
"grunt-contrib-clean" : "*",
"grunt-contrib-jshint" : "*",
"grunt-version-check" : "*"
"grunt-version-check" : "*",
"grunt-eslint" : "*"
},
"licenses": [
{
Expand Down

0 comments on commit 72a58de

Please sign in to comment.