Skip to content

Commit

Permalink
eslint:recommended (#1790)
Browse files Browse the repository at this point in the history
* eslint:recommended
  • Loading branch information
msimerson committed Jan 31, 2017
1 parent fa113ab commit 51c01f7
Show file tree
Hide file tree
Showing 26 changed files with 148 additions and 129 deletions.
6 changes: 4 additions & 2 deletions .eslintrc.json
Expand Up @@ -2,9 +2,11 @@
"plugins": [
"haraka"
],
"extends": ["plugin:haraka/recommended"],
"extends": ["eslint:recommended", "plugin:haraka/recommended"],
"rules": {
"no-console": 0,
"no-empty": ["error", { "allowEmptyCatch": true }]
"no-empty": ["error", { "allowEmptyCatch": true }],
"no-cond-assign": ["error", "except-parens"],
"no-constant-condition": ["error", { "checkLoops": false }]
}
}
23 changes: 0 additions & 23 deletions .jshintrc

This file was deleted.

49 changes: 26 additions & 23 deletions bin/haraka
@@ -1,5 +1,4 @@
#!/usr/bin/env node
/*eslint no-shadow: ["error", { "allow": ["config", "smtp_ini"] }]*/

// this script takes inspiration from:
// https://github.com/visionmedia/express/blob/master/bin/express
Expand Down Expand Up @@ -132,15 +131,15 @@ function mkDir (dstPath) {
try {
if (fs.statSync(dstPath).isDirectory()) return;
}
catch (ignore) {};
catch (ignore) {}

try {
fs.mkdirSync(dstPath, fs.statSync(__dirname).mode);
create(dstPath)
}
catch (e) {
// File exists
if (e.errno = 17) {
if (e.errno == 17) {
warning(e.message);
}
else {
Expand Down Expand Up @@ -186,13 +185,13 @@ function copyFile (srcFile, dstFile) {
// File exists
warning("EEXIST, File exists '" + dstFile + "'");
return;
};
}
// Something other than a file exists
throw "EEXIST but not a file: '" + dstFile + "'";
}
catch (e) {
// File NOT exists
if (e.errno = 2) {
if (e.errno == 2) {
fs.writeFileSync(dstFile, fs.readFileSync(srcFile));
create(dstFile)
}
Expand Down Expand Up @@ -298,6 +297,10 @@ function createFile (filePath, data, info) {
}
}

var config;
var logger;
var outbound;
var plugins;
if (parsed.version) {
console.log("\033[32;40mHaraka.js\033[0m — Version: " + ver);
}
Expand Down Expand Up @@ -340,7 +343,7 @@ else if (parsed.help) {
var pager_split = process.env.PAGER.split(/ +/);
pager = pager_split.shift();
md_path = pager_split.concat(md_path);
};
}

var less = spawn( pager, md_path, { stdio: 'inherit' } );
less.on('exit', function () {
Expand All @@ -367,10 +370,10 @@ else if (parsed.qlist) {
fail("qlist option requires config path");
}
process.env.HARAKA = parsed.configs;
var logger = require(path.join(base, "logger"));
logger = require(path.join(base, "logger"));
if (!parsed.verbose)
logger.log = function () {} // disable logging for this
var outbound = require(path.join(base, "outbound"));
outbound = require(path.join(base, "outbound"));
outbound.list_queue(function (err, qlist) {
qlist.forEach(function (todo) {
console.log(sprintf("Q: %s rcpt:%d from:%s domain:%s", todo.file, todo.rcpt_to.length, todo.mail_from.toString(), todo.domain));
Expand All @@ -383,10 +386,10 @@ else if (parsed.qstat) {
fail("qlist option requires config path");
}
process.env.HARAKA = parsed.configs;
var logger = require(path.join(base, "logger"));
logger = require(path.join(base, "logger"));
if (!parsed.verbose)
logger.log = function () {} // disable logging for this
var outbound = require(path.join(base, "outbound"));
outbound = require(path.join(base, "outbound"));
outbound.stat_queue(function (err, stats) {
console.log(stats);
process.exit();
Expand All @@ -398,7 +401,7 @@ else if (parsed.qunstick) {
}
var domain = parsed.qunstick.toLowerCase();
process.env.HARAKA = parsed.configs;
var logger = require(path.join(base, "logger"));
logger = require(path.join(base, "logger"));
if (!parsed.verbose)
logger.log = function () {} // disable logging for this
var cb = function () {
Expand All @@ -416,12 +419,11 @@ else if (parsed.graceful) {
fail("graceful option requires config path");
}
process.env.HARAKA = parsed.configs;
var logger = require(path.join(base, "logger"));
logger = require(path.join(base, "logger"));
if (!parsed.verbose)
logger.log = function () {} // disable logging for this
var config = require(path.join(base, "config"));
var smtp_ini = config.get("smtp.ini");
if (!smtp_ini.main.nodes) {
config = require(path.join(base, "config"));
if (!config.get("smtp.ini").main.nodes) {
console.log("Graceful restart not possible without `nodes` value in smtp.ini");
process.exit();
}
Expand Down Expand Up @@ -453,10 +455,10 @@ else if (parsed.order) {
require('module')._initPaths(); // Horrible hack
}
require(path.join(base, 'configfile')).watch_files = false;
var logger = require(path.join(base, "logger"));
logger = require(path.join(base, "logger"));
if (!parsed.verbose)
logger.log = function () {} // disable logging for this
var plugins = require(path.join(base, "plugins"));
plugins = require(path.join(base, "plugins"));
plugins.load_plugins();
console.log('');
var hooks = Object.keys(plugins.registered_hooks);
Expand Down Expand Up @@ -489,7 +491,7 @@ else if (parsed.test) {
require('module')._initPaths(); // Horrible hack
}
require(path.join(base, 'configfile')).watch_files = false;
var logger = require(path.join(base, "logger"));
logger = require(path.join(base, "logger"));
logger.loglevel = logger.levels.PROTOCOL;

// Attempt to load message early
Expand All @@ -504,7 +506,7 @@ else if (parsed.test) {
}
}

var plugins = require(path.join(base, "plugins"));
plugins = require(path.join(base, "plugins"));
plugins.server = { notes: {} };
plugins.load_plugins((parsed.test && parsed.test[0] !== 'all') ? parsed.test : null);
var Connection = require(path.join(base, "connection"));
Expand Down Expand Up @@ -577,6 +579,7 @@ else if (parsed.test) {
// Add data to stream
if (msg) {
var buf = msg;
var offset;
while ((offset = utils.indexOfLF(buf)) !== -1) {
var line = buf.slice(0, offset+1);
if (buf.length > offset) {
Expand Down Expand Up @@ -634,11 +637,11 @@ else if (parsed.configs) {
fail( "No such directory: " + base_dir + "\n" + err_msg );
}

var smtp_ini = path.join(base_dir,'config','smtp.ini');
var smtp_ini_path = path.join(base_dir,'config','smtp.ini');
var smtp_json = path.join(base_dir,'config','smtp.json');
var smtp_yaml = path.join(base_dir,'config','smtp.yaml');
if (!fs.existsSync(smtp_ini) && !fs.existsSync(smtp_json) && !fs.existsSync(smtp_yaml)) {
fail( "No smtp.ini at: " + smtp_ini + "\n" + err_msg );
if (!fs.existsSync(smtp_ini_path) && !fs.existsSync(smtp_json) && !fs.existsSync(smtp_yaml)) {
fail( "No smtp.ini at: " + smtp_ini_path + "\n" + err_msg );
}

process.argv[1] = haraka_path;
Expand Down Expand Up @@ -667,7 +670,7 @@ else {
}

function send_internal_command (cmd, done) {
var config = require(path.join(base, "config"));
config = require(path.join(base, "config"));
var key = config.get("internalcmd_key");
var smtp_ini = config.get("smtp.ini");
var listen_addrs = require(path.join(base, "server")).get_listen_addrs(smtp_ini.main);
Expand Down
4 changes: 2 additions & 2 deletions bin/spf
Expand Up @@ -24,8 +24,8 @@ if (!parsed.debug) {
}

if (parsed.domain) {
var domain;
if (domain = /\@(.+)$/.exec(parsed.domain)) {
var domain = /\@(.+)$/.exec(parsed.domain);
if (domain) {
domain = domain[1];
}
else {
Expand Down
6 changes: 4 additions & 2 deletions chunkemitter.js
@@ -1,3 +1,5 @@
'use strict';

var util = require('util');
var EventEmitter = require('events').EventEmitter;

Expand Down Expand Up @@ -28,7 +30,7 @@ if (!Buffer.concat) {

if (typeof length !== 'number') {
length = 0;
for (var i = 0; i < list.length; i++) {
for (let i = 0; i < list.length; i++) {
buf = list[i];
length += buf.length;
}
Expand All @@ -37,7 +39,7 @@ if (!Buffer.concat) {
var buffer = new Buffer(length);
var pos = 0;

for (var i = 0; i < list.length; i++) {
for (let i = 0; i < list.length; i++) {
buf = list[i];
buf.copy(buffer, pos);
pos += buf.length;
Expand Down
39 changes: 21 additions & 18 deletions configfile.js
Expand Up @@ -5,6 +5,8 @@ var fs = require('fs');
var path = require('path');
var yaml = require('js-yaml');

var logger = getStubLogger();

// for "ini" type files
var regex = exports.regex = {
section: /^\s*\[\s*([^\]]*?)\s*\]\s*$/,
Expand Down Expand Up @@ -37,7 +39,7 @@ var config_dir_candidates = [

function get_path_to_config_dir () {
if (process.env.HARAKA) {
// console.log('process.env.HARAKA: ' + process.env.HARAKA);
// logger.logdebug('process.env.HARAKA: ' + process.env.HARAKA);
cfreader.config_path = path.join(process.env.HARAKA, 'config');
return;
}
Expand All @@ -64,24 +66,26 @@ function get_path_to_config_dir () {
}
}
catch (ignore) {
console.error(ignore.message);
logger.logerror(ignore.message);
}
}
}
get_path_to_config_dir();
// console.log('cfreader.config_path: ' + cfreader.config_path);

// Stubs that can be used before logger is loaded
var logger = {
logdebug: function () {
console.log.apply(console, arguments);
},
loginfo: function () {
console.log.apply(console, arguments);
},
logerror: function () {
console.error.apply(console, arguments);
},
// logger.logdebug('cfreader.config_path: ' + cfreader.config_path);

function getStubLogger () {
// stubs used before logger is loaded
return {
logdebug: function () {
console.log.apply(console, arguments);
},
loginfo: function () {
console.log.apply(console, arguments);
},
logerror: function () {
console.error.apply(console, arguments);
},
}
}

cfreader.on_watch_event = function (name, type, options, cb) {
Expand Down Expand Up @@ -375,7 +379,7 @@ cfreader.process_file_overrides = function (name, result) {
var cache_key = cfreader.get_cache_key(name);
if (cfreader._config_cache[cache_key]) {
var ck_keys = Object.keys(cfreader._config_cache[cache_key]);
for (var i=0; i<ck_keys.length; i++) {
for (let i=0; i<ck_keys.length; i++) {
if (ck_keys[i].substr(0,1) === '!') {
delete cfreader._config_cache[path.join(cfreader.config_path, ck_keys[i].substr(1))];
}
Expand All @@ -386,7 +390,7 @@ cfreader.process_file_overrides = function (name, result) {
// configuration file data using by prefixing the
// outer variable name with ! e.g. !smtp.ini
var keys = Object.keys(result);
for (var i=0; i<keys.length; i++) {
for (let i=0; i<keys.length; i++) {
if (keys[i].substr(0,1) === '!') {
var ofp = path.join(cfreader.config_path, keys[i].substr(1));
cfreader._overrides[ofp] = true;
Expand Down Expand Up @@ -619,5 +623,4 @@ cfreader.load_binary_config = function (name, type) {
}
}
};
var fs = require('fs');
logger = require('./logger');
4 changes: 3 additions & 1 deletion connection.js
Expand Up @@ -288,6 +288,7 @@ Connection.prototype.process_line = function (line) {
}

// Check for non-ASCII characters
/* eslint no-control-regex: 0 */
if (/[^\x00-\x7F]/.test(this.current_line)) {
// See if this is a TLS handshake
var buf = new Buffer(this.current_line.substr(0,3), 'binary');
Expand Down Expand Up @@ -532,7 +533,7 @@ Connection.prototype.respond = function (code, msg, func) {
var mess;
var buf = '';

while (mess = messages.shift()) {
while ((mess = messages.shift())) {
var line = code + (messages.length ? "-" : " ") +
(uuid ? '[' + uuid + '@' + hostname + '] ' : '' ) + mess;
this.logprotocol("S: " + line);
Expand Down Expand Up @@ -1172,6 +1173,7 @@ Connection.prototype.cmd_proxy = function (line) {
var dst_port = match[5];

// Validate source/destination IP
/*eslint no-fallthrough: 0 */
switch (proto) {
case 'TCP4':
if (ipaddr.IPv4.isValid(src_ip) && ipaddr.IPv4.isValid(dst_ip)) {
Expand Down
4 changes: 2 additions & 2 deletions dkim.js
Expand Up @@ -315,7 +315,7 @@ DKIMObject.prototype.end = function () {
self.debug(self.identity + ': got DNS record: ' + record);
var rec = record.replace(/\r?\n/g, '').replace(/\s+/g,'');
var split = rec.split(';');
for (var j=0; j<split.length; j++) {
for (let j=0; j<split.length; j++) {
var split2 = split[j].split('=');
if (split2[0]) self.dns_fields[split2[0]] = split2[1];
}
Expand Down Expand Up @@ -366,7 +366,7 @@ DKIMObject.prototype.end = function () {
}
else if (flag === 's') {
// 'i' and 'd' domain much match exactly
var j = self.fields.i;
let j = self.fields.i;
j = j.substr(j.indexOf('@')+1, j.length);
if (j !== self.fields.d) {
return self.result('domain mismatch', 'invalid');
Expand Down
2 changes: 1 addition & 1 deletion dsn.js
Expand Up @@ -84,7 +84,7 @@ function DSN (code, msg, def, subject, detail) {
if (Array.isArray(this.msg)) {
this.reply = [];
var m;
while (m = this.msg.shift()) {
while ((m = this.msg.shift())) {
this.reply.push([this.cls, this.sub, this.det].join('.') + ' ' + m);
}
}
Expand Down
2 changes: 1 addition & 1 deletion line_socket.js
Expand Up @@ -18,7 +18,7 @@ function setup_line_processor (socket) {
socket.process_data = function (data) {
current_data += data;
var results;
while (results = utils.line_regexp.exec(current_data)) {
while ((results = utils.line_regexp.exec(current_data))) {
var this_line = results[1];
current_data = current_data.slice(this_line.length);
socket.emit('line', this_line);
Expand Down

0 comments on commit 51c01f7

Please sign in to comment.