Skip to content

Commit

Permalink
es6 templates: replace concatenated strings (#2722)
Browse files Browse the repository at this point in the history
* es6 templates: replace concatenated strings
* github workflows: run also on PR
  • Loading branch information
msimerson authored Oct 25, 2019
1 parent 3b58133 commit 15a025f
Show file tree
Hide file tree
Showing 63 changed files with 339 additions and 356 deletions.
1 change: 1 addition & 0 deletions .eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ root: true

rules:
semi-style: [error, last]
prefer-template: "warn"
no-unneeded-ternary: 1

extends: ["eslint:recommended", "plugin:haraka/recommended"]
2 changes: 1 addition & 1 deletion .github/workflows/ci-test-win.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Haraka Tests - Windows

on: [push]
on: [ push, pull_request ]

# no docker/images support on Windows (currently), so run w/o Redis
# also, stack run commands so test doesn't begin before install completes
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci-test.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Haraka Tests

on: [ push ]
on: [ push, pull_request ]

jobs:

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/lint.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Haraka Lint

on: [ push ]
on: [ push, pull_request ]

jobs:

Expand Down
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

### Changes

* lint: add 'prefer-template'
* restore TLS version info, set correctly #2723

### New features
Expand Down
4 changes: 2 additions & 2 deletions bin/dkimverify
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
const nopt = require('nopt');
const path = require('path');
const base_path = path.join(__dirname, '..');
const dkim = require(base_path + '/dkim');
const dkim = require(`${base_path}/dkim`);
const DKIMVerifyStream = dkim.DKIMVerifyStream;

const parsed = nopt({ 'debug': Boolean });
Expand All @@ -28,7 +28,7 @@ const verifier = new DKIMVerifyStream(function (err, result, results) {
});
}
else {
console.log('Result: ' + result);
console.log(`Result: ${result}`);
}
});

Expand Down
72 changes: 36 additions & 36 deletions bin/haraka
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const mkdirp = require('mkdirp');
const utils = require('haraka-utils');
const sprintf = require('sprintf-js').sprintf;
const base = path.join(__dirname, '..');
const ver = JSON.parse(fs.readFileSync(base+'/package.json', 'utf8')).version;
const ver = JSON.parse(fs.readFileSync(`${base}/package.json`, 'utf8')).version;
const knownOpts = {
"version": Boolean,
"verbose": Boolean,
Expand Down Expand Up @@ -90,23 +90,23 @@ function listPlugins (b, dir) {

if (!dir) { dir = "plugins/"; }

let plist = dir + "\n";
let plist = `${dir}\n`;
const subdirs = [];
const gl = path.join((b ? b : base), dir);
const pd = fs.readdirSync(gl);

pd.forEach(function (p) {
const stat = fs.statSync(gl + '/' + p);
const stat = fs.statSync(`${gl}/${p}`);
if (stat.isFile() && ~p.search('.js')) {
plist += "\t" + p.replace('.js', '') + "\n";
plist += `\t${p.replace('.js', '')}\n`;
}
else if (stat.isDirectory()) {
subdirs.push(dir + p + "/");
subdirs.push(`${dir + p}/`);
}
});

subdirs.forEach(function (s) {
plist += "\n" + listPlugins(b, s);
plist += `\n${listPlugins(b, s)}`;
});

return plist;
Expand All @@ -115,16 +115,16 @@ function listPlugins (b, dir) {

// Show message when create
function create (dirPath) {
console.log('\x1b[32mcreate\x1b[0m: ' + dirPath);
console.log(`\x1b[32mcreate\x1b[0m: ${dirPath}`);
}

// Warning messsage
function warning (msg) {
console.error('\x1b[31mwarning\x1b[0m: ' + msg);
console.error(`\x1b[31mwarning\x1b[0m: ${msg}`);
}

function fail (msg) {
console.error('\x1b[31merror\x1b[0m: ' + msg);
console.error(`\x1b[31merror\x1b[0m: ${msg}`);
process.exit(-1);
}

Expand Down Expand Up @@ -286,15 +286,15 @@ const plugin_doc = [
function createFile (filePath, data, info) {
try {
if (fs.existsSync(filePath) && !parsed.force) {
throw filePath + " already exists";
throw `${filePath} already exists`;
}
mkDir(path.dirname(filePath));
const fd = fs.openSync(filePath, 'w');
const output = data.replace(/%(\w+)%/g, function (i, m1) { return info[m1] });
fs.writeSync(fd, output, null);
}
catch (e) {
warning("Unable to create file: " + e);
warning(`Unable to create file: ${e}`);
}
}

Expand All @@ -303,12 +303,12 @@ let logger;
let outbound;
let plugins;
if (parsed.version) {
console.log("\033[32;40mHaraka.js\033[0m — Version: " + ver);
console.log(`\x1B[32;40mHaraka.js\x1B[0m — Version: ${ver}`);
}
else if (parsed.list) {
console.log("\033[32;40m*global\033[0m\n" + listPlugins());
console.log(`\x1B[32;40m*global\x1B[0m\n${ listPlugins() }`);
if (parsed.configs) {
console.log("\033[32;40m*local\033[0m\n" + listPlugins(parsed.configs));
console.log(`\x1B[32;40m*local\x1B[0m\n${ listPlugins(parsed.configs) }`);
}
}
else if (parsed.help) {
Expand All @@ -318,14 +318,14 @@ else if (parsed.help) {
else {
let md_path;
const md_paths = [
path.join(base, 'docs', parsed.help + '.md'),
path.join(base, 'docs', 'plugins', parsed.help + '.md'),
path.join(base, 'docs', 'deprecated', parsed.help + '.md'),
path.join(base, 'node_modules', 'haraka-plugin-' + parsed.help, 'README.md'),
path.join(base, 'docs', `${parsed.help}.md`),
path.join(base, 'docs', 'plugins', `${parsed.help}.md`),
path.join(base, 'docs', 'deprecated', `${parsed.help}.md`),
path.join(base, 'node_modules', `haraka-plugin-${parsed.help}`, 'README.md'),
];
if (parsed.configs) {
md_paths.unshift(path.join(parsed.configs, 'docs', 'plugins', parsed.help + '.md'));
md_paths.unshift(path.join(parsed.configs, 'docs', parsed.help + '.md'));
md_paths.unshift(path.join(parsed.configs, 'docs', 'plugins', `${parsed.help}.md`));
md_paths.unshift(path.join(parsed.configs, 'docs', `${parsed.help}.md`));
}
for (let i=0, j=md_paths.length; i<j; i++) {
const _md_path = md_paths[i];
Expand All @@ -335,7 +335,7 @@ else if (parsed.help) {
}
}
if (!md_path) {
warning("No documentation found for: " + parsed.help);
warning(`No documentation found for: ${parsed.help}`);
process.exit();
}
let pager = 'less';
Expand All @@ -353,18 +353,18 @@ else if (parsed.help) {
}
}
else if (parsed.configs && parsed.plugin) {
const js_path = path.join(parsed.configs, 'plugins', parsed.plugin + '.js');
const js_path = path.join(parsed.configs, 'plugins', `${parsed.plugin}.js`);
createFile(js_path,
plugin_src, { plugin: parsed.plugin, config: parsed.configs });

const doc_path = path.join(parsed.configs, 'docs', 'plugins', parsed.plugin + '.md');
const doc_path = path.join(parsed.configs, 'docs', 'plugins', `${parsed.plugin}.md`);
createFile(doc_path,
plugin_doc, { plugin: parsed.plugin, config: parsed.configs });

console.log("Plugin " + parsed.plugin + " created");
console.log("Now edit javascript in: " + js_path);
console.log("Add the plugin to config: " + path.join(parsed.configs, 'config', 'plugins'));
console.log("And edit documentation in: " + doc_path);
console.log(`Plugin ${parsed.plugin} created`);
console.log(`Now edit javascript in: ${js_path}`);
console.log(`Add the plugin to config: ${path.join(parsed.configs, 'config', 'plugins')}`);
console.log(`And edit documentation in: ${doc_path}`);
}
else if (parsed.qlist) {
if (!parsed.configs) {
Expand Down Expand Up @@ -412,7 +412,7 @@ else if (parsed.qunstick) {
send_internal_command('flushQueue', cb);
}
else {
send_internal_command('flushQueue ' + domain, cb);
send_internal_command(`flushQueue ${domain}`, cb);
}
}
else if (parsed.graceful) {
Expand Down Expand Up @@ -450,7 +450,7 @@ else if (parsed.order) {
}
catch (e) {
process.env.NODE_PATH = process.env.NODE_PATH ?
(process.env.NODE_PATH + ':' + path.join(process.env.HARAKA, 'node_modules'))
(`${process.env.NODE_PATH}:${path.join(process.env.HARAKA, 'node_modules')}`)
:
(path.join(process.env.HARAKA, 'node_modules'));
require('module')._initPaths(); // Horrible hack
Expand All @@ -464,7 +464,7 @@ else if (parsed.order) {
const hooks = Object.keys(plugins.registered_hooks);
for (let h = 0; h < hooks.length; h++) {
const hook = hooks[h];
console.log(sprintf('%\'--80s', 'Hook: ' + hook + ' '));
console.log(sprintf('%\'--80s', `Hook: ${hook} `));
console.log(sprintf('%-35s %-35s %-4s %-3s', 'Plugin', 'Method', 'Prio', 'T/O'));
console.log(sprintf("%'-80s",''));
for (let p=0; p<plugins.registered_hooks[hook].length; p++) {
Expand All @@ -485,7 +485,7 @@ else if (parsed.test) {
}
catch (e) {
process.env.NODE_PATH = process.env.NODE_PATH ?
(process.env.NODE_PATH + ':' + path.join(process.env.HARAKA, 'node_modules'))
(`${process.env.NODE_PATH}:${path.join(process.env.HARAKA, 'node_modules')}`)
:
(path.join(process.env.HARAKA, 'node_modules'));
require('module')._initPaths(); // Horrible hack
Expand Down Expand Up @@ -602,7 +602,7 @@ else if (parsed.test) {
const args = arguments;
// Dump MIME structure and decoded body text?
function dump_mime_structure (body) {
console.log('Found MIME part ' + body.ct);
console.log(`Found MIME part ${body.ct}`);
console.log(body.bodytext);
for (let m=0,l=body.children.length; m < l; m++) {
dump_mime_structure(body.children[m]);
Expand Down Expand Up @@ -633,16 +633,16 @@ else if (parsed.configs) {
const haraka_path = path.join(base, 'haraka.js');

const base_dir = process.argv[3];
const err_msg = "Did you install a Haraka config? (haraka -i " + base_dir +")";
const err_msg = `Did you install a Haraka config? (haraka -i ${base_dir })`;
if (!fs.existsSync(base_dir)) {
fail( "No such directory: " + base_dir + "\n" + err_msg );
fail( `No such directory: ${base_dir}\n${err_msg}` );
}

const smtp_ini_path = path.join(base_dir,'config','smtp.ini');
const smtp_json = path.join(base_dir,'config','smtp.json');
const smtp_yaml = path.join(base_dir,'config','smtp.yaml');
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 );
fail( `No smtp.ini at: ${smtp_ini_path}\n${err_msg}` );
}

process.argv[1] = haraka_path;
Expand Down Expand Up @@ -678,7 +678,7 @@ function send_internal_command (cmd, done) {
const sock = net.connect(hp[2], hp[1], function () {
sock.once('data', function (data) {
// this is the greeting. Ignore it...
sock.write('INTERNALCMD ' + (key ? ('key:' + key + ' ') : '') + cmd + '\r\n');
sock.write(`INTERNALCMD ${key ? (`key:${key} `) : ''}${cmd}\r\n`);
sock.once('data', function (data2) {
console.log(data2.toString().replace(/\r?\n$/, ''));
sock.write('QUIT\r\n');
Expand Down
8 changes: 4 additions & 4 deletions dkim.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ class DKIMObject {

if (!header_name) return header;

let hc = header_name.toLowerCase() + ':' + header_value;
let hc = `${header_name.toLowerCase()}:${header_value}`;
hc = hc.replace(/\r\n([\t ]+)/g, "$1");
hc = hc.replace(/[\t ]+/g, ' ');
hc = hc.replace(/[\t ]+(\r?\n)$/, "$1");
Expand Down Expand Up @@ -376,9 +376,9 @@ class DKIMObject {
if (!self.dns_fields.p) return self.result('key revoked', 'invalid');

// crypto.verifier requires the key in PEM format
self.public_key = '-----BEGIN PUBLIC KEY-----\r\n' +
self.dns_fields.p.replace(/(.{1,76})/g, '$1\r\n') +
'-----END PUBLIC KEY-----\r\n';
self.public_key = `-----BEGIN PUBLIC KEY-----\r\n${
self.dns_fields.p.replace(/(.{1,76})/g, '$1\r\n')
}-----END PUBLIC KEY-----\r\n`;

let verified;
try {
Expand Down
6 changes: 3 additions & 3 deletions logger.js
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ logger.log_if_level = (level, key, plugin) => function () {
if (data instanceof connection.Connection) {
logobj.uuid = data.uuid;
if (data.tran_count > 0) {
logobj.uuid += "." + data.tran_count;
logobj.uuid += `.${data.tran_count}`;
}
}
else if (data instanceof plugins.Plugin) {
Expand Down Expand Up @@ -314,9 +314,9 @@ logger.add_log_methods = (object, plugin) => {
if (!object) return;
if (typeof(object) !== 'object') return;
for (const level in logger.levels) {
const fname = 'log' + level.toLowerCase();
const fname = `log${level.toLowerCase()}`;
if (object[fname]) continue; // already added
object[fname] = logger.log_if_level(level, 'LOG'+level, plugin);
object[fname] = logger.log_if_level(level, `LOG${level}`, plugin);
}
}

Expand Down
2 changes: 1 addition & 1 deletion mailheader.js
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ function _decode_rfc2231 (params, str) {
/* eslint no-constant-condition: 0 */
let merged = '';
for (let i=0; true; i++) {
const _key = key + '*' + i;
const _key = `${key}*${i}`;
const _val = params.kv[_key];
if (_val === undefined) break;
merged += _val;
Expand Down
2 changes: 1 addition & 1 deletion outbound/qfile.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const os = require('os');
const platform_dot = ((['win32','win64'].includes(process.platform)) ? '' : '__tmp__') + '.';
const platform_dot = `${(['win32','win64'].includes(process.platform)) ? '' : '__tmp__'}.`;

let QFILECOUNTER = 0;

Expand Down
5 changes: 2 additions & 3 deletions outbound/queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ exports._load_cur_queue = (pid, iteratee, cb) => {
logger.loginfo("[outbound] Loading outbound queue from ", queue_dir);
fs.readdir(queue_dir, (err, files) => {
if (err) {
return logger.logerror("[outbound] Failed to load queue directory (" +
queue_dir + "): " + err);
return logger.logerror(`[outbound] Failed to load queue directory (${queue_dir}): ${err}`);
}

self.cur_time = new Date(); // set once so we're not calling it a lot
Expand All @@ -106,7 +105,7 @@ exports.read_parts = file => {

const parts = _qfile.parts(file);
if (!parts) {
logger.logerror("[outbound] Unrecognized file in queue folder: " + file);
logger.logerror(`[outbound] Unrecognized file in queue folder: ${file}`);
return false;
}

Expand Down
2 changes: 1 addition & 1 deletion outbound/timer_queue.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class TimerQueue {
}

drain () {
logger.logdebug("Draining " + this.queue.length + " items from the queue");
logger.logdebug(`Draining ${this.queue.length} items from the queue`);
while (this.queue.length) {
const to_run = this.queue.shift();
if (to_run.cb) to_run.cb();
Expand Down
4 changes: 2 additions & 2 deletions plugins.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class Plugin {
}

try {
return '"use strict";' + fs.readFileSync(pp);
return `"use strict";${fs.readFileSync(pp)}`;
}
catch (err) {
if (exports.config.get('smtp.ini').main.ignore_bad_plugins) {
Expand Down Expand Up @@ -498,7 +498,7 @@ plugins.run_next_hook = (hook, object, params) => {
}
}

const respond_method = hook + '_respond';
const respond_method = `${hook}_respond`;
if (item && is_deny_retval(retval) && hook.substr(0,5) !== 'init_') {
object.deny_respond =
get_denyfn(object, hook, params, retval, msg, respond_method);
Expand Down
Loading

0 comments on commit 15a025f

Please sign in to comment.